当我尝试运行我的代码时:
Testing.html -测试.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中正常运行的简单示例。我是做错了什么还是只有Google Chrome不能运行这个代码?