我正在尝试从模态弹出窗口对我的父类进行简单调用,但 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/