Javascript 在Iframe中单击任何链接时如何获取url?
我试图在不修改链接代码的情况下检索iframe中任何单击的URL。我的目标是获得一个用户在iframe主体之外的iframe中单击的URL。我已经尝试了以下方法:Javascript 在Iframe中单击任何链接时如何获取url?,javascript,html,url,iframe,Javascript,Html,Url,Iframe,我试图在不修改链接代码的情况下检索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);
document.write(location.href);
document.write(window.location.href);
document.write(window.location);
document.write(document.URL);
document.write(document.location);
不要认为这可能只适用于来自同一个域的内容。如果你写了这篇文章,它应该在作为iframe源的页面正文中。我不能修改进入iframe的内容,是否仍然可能?这就是问题所在,内容或iframe源不在同一个域中,我不允许修改它的源。然后,要使其正常工作,您只能购买显示内容的域;)
document.getElementById("myFrame")
.contentDocument.addEventListener("click", yourfunction, false);