【问题标题】:How to get the url when any link is clicked in Iframe?在 iframe 中单击任何链接时如何获取 url?
【发布时间】:2013-08-25 23:27:13
【问题描述】:

我正在尝试在不修改链接代码的情况下检索 iframe 内的任何点击 URL。我的目标是让用户在 iframe 正文之外单击 iframe 的 URL。我已经尝试了以下方法:

document.write(location.href);
document.write(window.location.href);
document.write(window.location);
document.write(document.URL);
document.write(document.location);

【问题讨论】:

  • 你写这个的地方,它应该在你的 iframe 来源的页面正文中
  • 我不能修改进入iframe的内容,还有可能吗?

标签: javascript html url iframe


【解决方案1】:
document.getElementById("myFrame")
.contentDocument.addEventListener("click", yourfunction, false);

不要认为这可能仅适用于来自同一 domain 的内容。

【讨论】:

  • 这是问题所在,内容或 iframe 源不在同一个域中,我不允许修改它的源。
  • 那么,你唯一能做的就是购买你展示内容的域名;)
猜你喜欢
  • 2017-04-11
  • 2012-02-25
  • 1970-01-01
  • 1970-01-01
  • 2017-10-06
  • 2016-01-20
  • 1970-01-01
  • 2018-05-31
  • 1970-01-01
相关资源
最近更新 更多