我在IFRAME开放和外部网站。如何捕获在iframe中的外部网站点击的确切链接?

问题描述 投票:1回答:1

我有一个包含Iframe的页面。我已经在iframe中打开了一个外部网站。我想使用纯javascipt捕获在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 javascript-events
1个回答
0
投票
document.getElementsByTagName("a").forEach(function(el){
     el.addEventListener("click", function(el){
         //here is your link value
         var link = el.currentTarget.getAttribute('href');
         //return false;
     });
});
© www.soinside.com 2019 - 2024. All rights reserved.