答え
ブラウザに作業を行う時間を与えてみてください(サイズ変更が表示されることに少し驚いています):
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で問題なく動作し、他ではテストされていませんが、問題はないと思います。