Answer
Try giving the browser a moment to do the work (I'm a bit surprised the resize shows up):
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();
}
}
Note that the Block
form won't be submitted until finish
gets called, so if your logic is assuming that's synchronous, it may be an issue.
Demo
The parent page:
<!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>
The popup page:
<!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>
I haven't included the showparams.jsp
page that the form is submitted to, but all it does is dump out the fields that were submitted. The above works just fine in Chrome and IE7, didn't test it in others but I wouldn't expect a problem.