document.frame在ie11中不工作
我在ie 11中执行时遇到未定义的对象错误,但没有兼容模式。它在ie 11兼容模式下工作正常。document.frame在ie11中不工作
示例代码:
<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")
我已经试过了。它返回null。 – pranav 2015-04-02 04:31:12
@pranav - 已经尝试了什么?你正在用'id =“iframe_tabCust”'插入一个元素。除非你使用HTML或错误的地方,否则你应该可以用'document.getElementById(“iframe_tabCust”)''来找到那个元素。我建议你排除为什么这不起作用,因为这是对此进行编码的明显方式。提供给我们一个jsFiddle演示,我们将为您进行调试。 – jfriend00 2015-04-02 04:35:02
@pranav - FYI,'document.getElementById(“iframe_tabCust”)'在这里工作正常:http://jsfiddle.net/jfriend00/4eob4gar/所以在你真实的代码中一定还有其他的事情你还没有透露。另外,你为什么要花13小时回答问题。如果你走了那么久,这个网站不能很好地工作。 – jfriend00 2015-04-02 04:40:46
好一个节点不应该有一个文档,它应该
window.frames["iframe_tabCust"]
或只是ID引用它
document.getElementById("iframe_tabCust")
我已经试过这个。它返回undefined – pranav 2015-04-02 04:31:58
请使用将来的代码格式,而不是报价块。我编辑它,所以它显示正确。 – epascarello 2015-04-01 15:17:47
如果你删除'document.',它会起作用吗?那就是'var test = node.frames [“iframe_tabCust”];'。 – Xufox 2015-04-01 15:20:04
没有它没有工作。它返回无法获得财产。 – pranav 2015-04-02 04:40:00