Forum Moderators: open
<input type="submit" name="mywar" value="Click" onclick="setTimeout('window.close()', 500)" />
I have tried window.close, window.self.close, self.close, and _windowname.close
but neither works. Please, if someone could let me know what I am doing wrong I'd be sincelely greatful.
Best,
Joe
[edited by: Joe_Belmaati at 7:12 pm (utc) on May 27, 2008]
Working example, the escapes \ are only because I did a document.write() to my new window. Set the timeout to 2000 to verify.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- doctype all on one line! -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Set Timeout</title>
<script type="text/javascript">
function newWin() {
var day = new Date();
var id=day.getTime();
var params = 'width=400,height=400,scrollbars,resizable';
var msg='<p><a href="#" onClick="setTimeout(\'window.close()\',500);return false;">'+
'This window will self-destruct half a second after you click this link</a></p>'+
'<form><input type="button" onClick="setTimeout(\'window.close()\',500);"'+
' value="Or click this button"></form>';
var win=open('',id,params);
win.document.write(msg);
win.document.close();
return false;
}
</script>
</head>
<body>
<p><a href="#" onClick="return newWin();">open new window</a></p>
</body>
</html>
onclick="setTimeout('popWindow.close()',500);"
having changed the launch code to
onclick="popWindow=window.open('airport.php?mode=edit&id=20&aid=1', '_editwindow', 'resizable=0,width=800,height=440,top=200,left=200'); return false;">
...but for some reason the window still does not want to close. ... :-(
"outside of all functions should declare
var popWindow;"
Sorry to sound like a rookie, but how do I do that? Thank you so much for your help.
[edited by: Joe_Belmaati at 12:50 pm (utc) on May 28, 2008]
When you open the pop up you will need to save its handle in global var
This shouldn't be necessary, see my previous example. window.close() will reference the current window in any case, which is the current popup window. This is why I thought you were trying to close the "opener" window.
Perhaps a full code snippet, as I did in my working example, would be helpful.
[edit] AH. I just tried this in Internet Exploder, and locally, I'm getting the "Internet Explorer has restricted this page" warning. If you have that disabled or are ignoring it, try your server version?
I was assuming you were trying to close the popup from the main window, you mention two onclicks, the one that opens the pop up is assumably within the main page, where is the other ?
If you wish to open the popup and unconditionly close it after a period then try in main page
<script>
var popWindow;
</script>
...
<body>
...
onclick="popWindow=window.open('airport.php?mode=edit&id=20&aid=1', '_editwindow', 'resizable=0,width=800,height=440,top=200,left=200'); setTimeout('popWindow.close()',500); return false;">
...
</body>
<input type="submit" name="mywar" value="Click" onclick="setTimeout('window.close()', 500)" />
Looking back at your original post, I see you are doing this on the submit button, when the timeout occurs the submit reply may or may not have completed.
Consider putting the window close logic in the submit reply page.
Once again thank you so much for your help. I sincerely appreciate it :-)
[edited by: Joe_Belmaati at 8:29 am (utc) on May 31, 2008]