IE 9 Javascript Window Variable 为 null.适用于IE 8

IE 9 Javascript Window Variable is null.. Works on IE 8

本文关键字:IE null 适用于 Variable Javascript Window      更新时间:2023-09-26

在我的代码中的某个时刻,我以这种方式访问一个javascript变量:

var DASHBOARD = document.parentWindow.parent.Dashboard;

其中 parent 的值是 {object Window},其类型是 DispHTMLWindow2。它在IE8或IE9兼容性视图中工作正常,但是当我无法使其在IE9上工作时。

在IE9上,document.parentWindow.parent.Dashboard的值是未定义的,其类型是Undefined的。我还注意到 parent 的值是 {...},它在 IE 9 上的类型是 [对象,窗口]。

在IE 9中是否有其他方法可以访问变量仪表板?

例:

布局.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Create new Layout</title>
    <style type="text/css">
        .border-top { height: 5px; background-color: #B2B2B2;}
        .border-left { width: 3px; height: 100%; background-color: #B2B2B2;}
        .content { height: 100%; background-color: #FFFFFF;}
    </style>
    <script type="text/javascript" src="./container/includes/js/jquery-1.5.1.min.js"></script>
    <script type="text/javascript" src="./container/includes/js/jquery-ui-1.8.12.custom.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var dada = "123";
        });
    </script>
</head>
<body>
    <form id="form1" runat="server" style="width: 100%; height: 100%;">
    <div style="width: 100%; height: 100%;">
        <iframe name="remote_iframe_0" src="layouts2.aspx" id="remote_iframe_0" />
    </div>
    </form>
</body>
</html>

布局2.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .border-top { height: 5px; background-color: #B2B2B2;}
        .border-left { width: 3px; height: 100%; background-color: #B2B2B2;}
        .content { height: 100%; background-color: #FFFFFF;}
    </style>
    <script type="text/javascript" src="./container/includes/js/jquery-1.5.1.min.js"></script>
    <script type="text/javascript" src="./container/includes/js/jquery-ui-1.8.12.custom.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            debugger;
        });
    </script>
</head>
<body>
    <form id="form1" runat="server" style="width: 100%; height: 100%;">
    <div style="width: 100%; height: 100%;">
        AAAA
    </div>
    </form>
</body>
</html>

如何在调试器中访问变量 dada;在布局中2.aspx?考虑到两个页面位于同一域中。

您可以使用:

window.parent.dada

参考:

http://w3schools.com/jsref/obj_window.asp

http://w3schools.com/jsref/dom_obj_document.asp