0

そのため、子のポップアップウィンドウは、アラートボタンをクリックするまで閉じませんが、子のサイズ変更方法を使用すると、アラートが表示される前にサイズが変更されます。

親ページのコードは次のとおりです。

function ClosePopup(objWindow, strMessage) {
    objWindow.close();
    //objWindow.resizeTo(30, 30);
    if (strMessage != '') { alert(strMessage); }
    document.Block.submit();
}

そして、これがポップアップページのコードです:

$strShowMessage = "window.opener.ClosePopup(self, '$strReclassifiedLots');";

そして、そのコードは送信イベントの背後に置かれます。

4

1 に答える 1

1

答え

ブラウザに作業を行う時間を与えてみてください(サイズ変更が表示されることに少し驚いています):

function ClosePopup(objWindow, strMessage) {

    // Close the popup (or whatever)
    objWindow.close();
    //objWindow.resizeTo(30, 30);

    // Schedule our `finish` call to happen *almost* instantly;
    // this lets the browser do some UI work and then call us back
    setTimeout(finish, 0); // It won't really be 0ms, most browsers will do 10ms or so

    // Our `finish` call
    function finish() {
        if (strMessage != '') { alert(strMessage); }
        document.Block.submit();
    }
}

Blockフォームは呼び出されるまで送信されないfinishため、ロジックが同期していると想定している場合は、問題になる可能性があることに注意してください。

デモ

親ページ:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Popup Test Page</title>
<style type='text/css'>
body {
    font-family: sans-serif;
}
</style>
<script type='text/javascript'>

function ClosePopup(objWindow, strMessage) {

    // Close the popup (or whatever)
    objWindow.close();
    //objWindow.resizeTo(30, 30);

    // Schedule our `finish` call to happen *almost* instantly;
    // this lets the browser do some UI work and then call us back
    setTimeout(finish, 0); // It won't really be 0ms, most browsers will do 10ms or so

    // Our `finish` call
    function finish() {
        if (strMessage != '') { alert(strMessage); }
        document.Block.submit();
    }
}

</script>
</head>
<body><a href='popup.html' target='_blank'>Click for popup</a>
<form name='Block' action='showparams.jsp' method='POST'>
<input type='text' name='field1' value='Value in field1'>
</form>
</body>
</html>

ポップアップページ:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title>Popup</title>
<style type='text/css'>
body {
    font-family: sans-serif;
}
</style>
<script type='text/javascript'>
function closeMe() {
    window.opener.ClosePopup(window, "Hi there");
}
</script>
</head>
<body>
<input type='button' value='Close' onclick="closeMe();">
</body>
</html>

showparams.jspフォームが送信されたページは含めていませんが、送信されたフィールドをダンプするだけです。上記はChromeとIE7で問題なく動作し、他ではテストされていませんが、問題はないと思います。

于 2010-05-12T12:38:11.457 に答える