gpt4 book ai didi

javascript - document.frame 在 ie11 中不起作用

转载 作者:行者123 更新时间:2023-12-03 10:26:05 24 4
gpt4 key购买 nike

在没有兼容模式的 ie 11 中执行时,出现 undefined object 错误。它在 ie 11 兼容模式下工作正常。

示例代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function test() {
var parent = document.getElementById("tabPaneMain");
var doc = document;
var html = '<div class="tab-page" id="tabCust" style="width: 100%; height: 95%">'
+ '<h2 class="tab">Customer</h2>'
+ '<table cellpadding=2 cellspacing=0 width="100%" height="100%">'
+ '<tr><td valign=top id=iframeparent_tabCust>'
+ '<iframe name="iframe_tabCust" id="iframe_tabCust" src="overview.html" style="width=100%; height: 100%;" scrolling="no" frameborder=0></iframe>'
+ '</td></tr></table></div>';

var node = doc.createElement("DIV");
node.innerHTML = html;
parent.appendChild(node);
var test = node.document.frames["iframe_tabCust"];// undefined error: when execute in ie 11 without compatibile mode

}
</script>
</head>
<body>
<div class="tab-pane" id="tabPaneMain" style="left: 10px; height: 100%" />
<button id="btn" type="button" onclick="test();">
click
</button>
</body>
</html>

提前致谢

最佳答案

您的 node 变量是一个 div 元素。上次我检查过,div 没有 document 属性。因此 node.document 将是未定义的,因此 node.document.frames 将是一个错误。

window.frames 是获取框架列表的标准位置。

<小时/>

由于您的框架上有一个唯一的 ID,因此获取框架的最简单且“支持跨浏览器”的方法可能是:

document.getElementById("iframe_tabCust")

关于javascript - document.frame 在 ie11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29394435/

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