我有一个 iFrame,其内容在另一个 iFrame 内。我想使用 JavaScript 获取内部 iFrame 的 src
内容。应该如何实现?
我有一个 iFrame,其内容在另一个 iFrame 内。我想使用 JavaScript 获取内部 iFrame 的 src
内容。应该如何实现?
外部页面:
<html>
<body>
<iframe id="ifr1" src="page1.htm"></iframe>
<iframe id="ifr2" src="http://www.google.com"></iframe>
</body>
</html>
page1.htm:
<html>
<body>
<script type="text/javascript">
document.write(parent.document.getElementById('ifr2').src);
</script>
</body>
</html>
<body>
<div id="f1" style="padding-left:5px;">..</div>
<script type="text/javascript"></script>
</body>
</html>
我不是很专业,但这些是关于你的脚本提示,你可以修改并测试你的页面。
iframeInstance.contentWindow.document - 这个文档从 SRC URL 加载。 而相反,要从内部文档返回父文档,请使用: parent.document
var newUrl = document.getElementById('iframeNestedFirst').contentWindow.document.getElementById('iframeExternalNestedWithinFirst').src;
步骤B)在新页面上打开包含运行时令牌的检测到的URL
window.open(newUrl).focus(); or window.open(newUrl,'_blank').focus();