document.frame在ie11中不起作用

时间:2015-04-01 15:10:18

标签: javascript

我在没有兼容模式的情况下执行时遇到未定义的对象错误。它在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>

提前致谢

2 个答案:

答案 0 :(得分:1)

您的node变量是div元素。最后我查了一下,div没有document属性。因此node.document将被取消定义,因此node.document.frames将是错误。

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


由于你的框架上有一个唯一的ID,可能是最简单的&#34;交叉浏览器支持&#34;获取框架的方法是:

document.getElementById("iframe_tabCust")

答案 1 :(得分:0)

一个节点不应该有一个文件,所以它应该是

window.frames["iframe_tabCust"]

或只是通过id

引用它
document.getElementById("iframe_tabCust")
相关问题