4

モーダルポップアップから親クラスへの簡単な呼び出しを試みていますが、IE はずっと私と戦っています。それを回避するための提案は大歓迎です。

以下は、私が使用しようとしているコードを削除したものです。FireFox では問題なく動作しますが、IE ではエラーがスローされます。「オブジェクトはこのプロパティまたはメソッドをサポートしていません」というエラーが表示され、「Catch」ブロックのコード行が参照されます。これは、Try ブロックと Catch ブロックの両方の行が機能しないことを意味します。

親.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>
4

2 に答える 2

0

IEモーダルダイアログは実際には真のウィンドウではなく、window.openerをサポートしていません。親ウィンドウを参照するには、次のようなダイアログ引数の一部としてウィンドウ参照を渡す必要があります。

    window.showModalDialog("topFrame1.html",["name", window],
    "dialogWidth:255px;dialogHeight:250px");

次に、次の行で子の親を参照できます。

    alert("1 "+ window.dialogArguments[1].getMainFrameVal());

ただし、私のアドバイスは、IEダイアログから完全に離れて、window.open()jQueryダイアログなどのすべてのブラウザーで機能する1つのソリューションを使用することです。

于 2011-11-29T00:24:50.643 に答える
0

window.openerでポップアップを開く際に使用しwindow.open()ます。

parent.html が topFrame1.html の親であり、密かにフレームセットなどを使用していないことは確かですか?

于 2011-11-29T00:17:20.460 に答える