Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Iframe中单击任何链接时如何获取url?_Javascript_Html_Url_Iframe - Fatal编程技术网

Javascript 在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);

我试图在不修改链接代码的情况下检索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的内容,是否仍然可能?这就是问题所在,内容或iframe源不在同一个域中,我不允许修改它的源。然后,要使其正常工作,您只能购买显示内容的域;)
document.getElementById("myFrame")
.contentDocument.addEventListener("click", yourfunction, false);