[英]iframe contentWindow is undefined when use window.frames[name] to access
如果使用以下方式获取contentWindow,则值为undefined
<html>
<head>
<title>iframe test</title>
</head>
<body>
<iframe id="frame1" src="frame1.html" name="frame1"></iframe>
<script>
document.body.onload = function() {
console.info("index loaded");
var frame1 = window.frames["frame1"];
console.info(frame1.contentWindow);
}
</script>
</body>
</html>
如果使用如下其他方式,它工作正常:
var frame1 = document.getElementById("frame1");
console.info(frame1.contentWindow);
我在 FF 29.0.1、chrome 34、IE11 上测试过,它们的工作方式都一样。
所以我有两个问题:
window.frames["frame1"];
是contentWindow
,它得到一个命名窗口,在你的情况下它与
document.getElementById("frame1").contentWindow
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.