如何在Iframe中单击任何链接时获取url

How to get the url when any link is clicked in Iframe?

本文关键字:链接 获取 url 任何 单击 Iframe      更新时间:2023-09-26

我试图在不修改链接代码的情况下检索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.getElementById("myFrame")
.contentDocument.addEventListener("click", yourfunction, false);

请注意,这可能只适用于来自同一域的内容。