By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,522 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Why won't windows.close() in function close the window?

100+
P: 103
I am learning java script watching tutorials and have created this simple code. The function executes 50%. When I click the button to close the window, the window.confirm appears and when I click okay, the window.close() should execute and close the window. The window does not close. Any suggestions or comments would be greatly appreciated. The simple code is below.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Pop-up Ad Example</title>
  3.     <head>
  4.         <Script language="javascript">
  5.             function closeWindow(form){
  6.             window.confirm("Are you sure you want to close this page?");
  7.  
  8.             window.close();
  9.         }
  10.         </script>
  11.     </head>
  12. <body>
  13.  
  14.         <form name="myform">
  15.             <input type="button" name="button" value="Close this Window" onClick="closeWindow(this.form)"></br>
  16.         </form>
  17. </body>
  18. </html>
  19.  
Jan 7 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
window.close() only works on windows you have previously opened with window.open().
Jan 7 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.