gpt4 book ai didi

javascript - 谷歌浏览器不接受 .contentDocument 或 .contentWindow

转载 作者:行者123 更新时间:2023-11-29 09:59:00 24 4
gpt4 key购买 nike

当我尝试我的代码时:

Testing.html -

<script language="JavaScript" type="text/javascript">
function find() {
var iframeEl = document.getElementById('love');
if ( iframeEl.contentDocument ) {
var form = iframeEl.contentDocument.document.getElementById('hi').getAttribute('href');
alert(form)
} else if ( iframeEl.contentWindow ) {
var form = iframeEl.contentWindow.document.getElementById('hi').getAttribute('href');
alert(form)
}
}
</script>
<body onload="find()">
<iframe name="lovez" src="frame.html" id="love"><a href="http://www.google.com" id="hi">Testingz</a></iframe>
</body>

Frame.html -

<a href="http://www.google.com" id="hi">Testing</a>

它不会返回警告框。但是在 Internet Explorer 上它会。我一直在互联网上搜索,尝试了所有示例,但找不到适用于 Google Chrome 的简单示例。我做错了什么还是只是谷歌浏览器?

最佳答案

我注意到如果代码来自 Web 服务器,contentDocumentgetSVGDocument(对于来自 svg 文件的 svg 对象)都可以正常工作,但是当我将代码复制到本地文件,它将不起作用。

Here's a sample link使用我从中复制的代码,该代码可在网络上使用,但不能从我的磁盘中使用。

Here's the solution我刚刚从 Chrome 中找到(感谢 Artem S),即使用 --allow-file-access-from-files 标志。

关于javascript - 谷歌浏览器不接受 .contentDocument 或 .contentWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5333878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com