我有一个包含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);
document.getElementsByTagName("a").forEach(function(el){
el.addEventListener("click", function(el){
//here is your link value
var link = el.currentTarget.getAttribute('href');
//return false;
});
});