当我尝试我的代码时:
测试.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>
Run Code Online (Sandbox Code Playgroud)
Frame.html -
<a href="http://www.google.com" id="hi">Testing</a>
Run Code Online (Sandbox Code Playgroud)
它不会返回警告框。但是在 Internet Explorer 上它会。我一直在互联网上搜索,尝试所有示例,但找不到可以在 Google Chrome 中使用的简单示例。我做错了什么还是只是谷歌浏览器?