我想從一個模式彈出窗口對我的父類進行簡單的調用,但IE瀏覽器一直在打我。任何建議來解決它將不勝感激。無法從IE7調用window.parent?
下面是我嘗試使用的精簡代碼。它在FireFox中工作良好,但在IE中引發錯誤 - 「對象不支持此屬性或方法」,引用「Catch」塊中的代碼行。這意味着Try和Catch塊中的行都不起作用。
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>
如果您發現有幫助的話,請不要忘記接受答案,如果您想澄清,請發表評論。 –