javascript - 无法从 IE7 调用 window.parent?

标签 javascript internet-explorer internet-explorer-7 popupwindow modalpopups

我正在尝试从模态弹出窗口对我的父类进行简单调用,但 IE 一直在与我作对。任何绕过它的建议将不胜感激。

下面是我尝试使用的精简代码。它在 FireFox 中运行良好,但在 IE 中抛出错误 - “对象不支持此属性或方法”,引用“Catch” block 中的代码行。这意味着 Try 和 Catch block 中的行都不起作用。

parent.html

<html><head>
<script>
function callMain(msg)
{
    alert(msg);
}

function modalWin() {
    if (window.showModalDialog) {
        window.showModalDialog("topFrame1.html","name",
        "dialogWidth:255px;dialogHeight:250px");
    } else {
        window.open('topFrame1.html','name',
        'toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes');
    }
}

function getMainFrameVal()
{
    return document.getElementById("mainframe").value;
}

</script>
</head> <body>
<a href="#" onclick="modalWin()" >PopUpWindow</a>
<form>
<input type=text id="mainframe" value="main"/>
</body></html>

topFrame1.html

<html><head>
<script type="text/javascript">
function getMain(){
try{
    alert("1 "+ window.opener.getMainFrameVal());
}catch(e)
{
    alert("2 " +window.parent.getMainFrameVal());
}
}
</script>
</head> <body>
TOP <a href="#" onclick="getMain()">click for main</a> <br/><br/>
</body></html>

最佳答案

window.opener 用于使用 window.open() 打开弹出窗口。

您确定 parent.html 是 topFrame1.html 的父级并且您没有 secret 使用框架集或其他东西吗?

关于javascript - 无法从 IE7 调用 window.parent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304010/

相关文章:

javascript - Node.js 中的 Hash_hmac 等效项

javascript - ServiceNow:JavaScript TypeError:无法读取未定义的属性

javascript - for-in JavaScript 语句中的 IE8 错误?

javascript - 带插件的圆 Angular 到 IE 7 中的图像?

css - 矩阵过滤器在 IE7 上对空白敏感吗?

javascript - Webstorm Karma 测试运行程序无法与 Yeoman Angular-fullstack 一起使用

javascript - 处理 JavaScript 属性区分大小写的策略

c# - 将 cookie 从 CookieContainer 写入 IE cookie 存储

html - 带有固定 <ul> 的 IE6 不工作

jquery - 使用IE7编辑placeholder属性