【问题标题】:I am opening and external website in IFRAME. How to capture exact link clicked in the external website which is in Iframe?我正在 IFRAME 中打开外部网站。如何捕获在 Iframe 中的外部网站中单击的确切链接?
【发布时间】:2018-08-30 07:21:16
【问题描述】:

我有一个包含 iframe 的页面。我已经在该 iframe 中打开了一个外部网站。我想捕获使用纯 Javascript 在 iframe 内单击的确切链接。下面是我的 iframe 代码。

<iframe id = "frame" src="" name="iframe_a" width = 100% height = 100% style="border:none;""> </iframe>

 

var monitor = setInterval(function()
{
var elem = document.activeElement;
if(elem && elem.tagName == 'IFRAME')
 {
    elem.blur();
    console.log(iframe_a.href);
  //console.log("clicked");
}
  }, 100);

【问题讨论】:

标签: javascript html events iframe dom-events


【解决方案1】:
document.getElementsByTagName("a").forEach(function(el){
     el.addEventListener("click", function(el){
         //here is your link value
         var link = el.currentTarget.getAttribute('href');
         //return false;
     });
});

【讨论】:

  • 您的答案可能是正确的,但解释会对其他读者有所帮助。欲了解更多信息,请阅读stackoverflow.com/help/how-to-answer
  • 我在 Iframe 中打开外部网站,我需要在 Iframe 中被点击的链接
  • 捕获 windows.location.href 终于为我工作了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-15
  • 2012-03-30
  • 1970-01-01
  • 2012-01-07
  • 2019-02-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多