jas*_*son 10 html javascript iframe
如果使用以下方式获取contentWindow,则该值未定义
<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>
Run Code Online (Sandbox Code Playgroud)
如果使用其他方式如下,它工作正常:
var frame1 = document.getElementById("frame1");
console.info(frame1.contentWindow);
Run Code Online (Sandbox Code Playgroud)
我测试了FF 29.0.1,chrome 34,IE11,它们都以相同的方式工作.
所以我有两个问题:
ade*_*neo 14
window.frames["frame1"];
Run Code Online (Sandbox Code Playgroud)
是contentWindow,它得到一个命名的窗口,在你的情况下,它是相同的东西
document.getElementById("frame1").contentWindow
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23984 次 |
| 最近记录: |