pranav
pranav

Reputation: 1

document.frame is not working in ie11

I am getting undefined object error while executing in ie 11 without compatible mode. it works fine in ie 11 compatible mode.

Sample code:

<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>

Thanks in advance

Upvotes: 0

Views: 3364

Answers (2)

epascarello
epascarello

Reputation: 207557

Well a node should not have a document so it should be

window.frames["iframe_tabCust"]

or just reference it by id

document.getElementById("iframe_tabCust")

Upvotes: 0

jfriend00
jfriend00

Reputation: 708016

Your node variable is a div element. Last I checked, a div doesn't have a document property. so node.document will be undefined and thus node.document.frames will be an error.

window.frames is the standard place where you get a list of frames.


Since you have a unique id on your frame, probably the simplest and "cross browser supported" way to obtain the frame is:

document.getElementById("iframe_tabCust")

Upvotes: 1

Related Questions