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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Connelly
    New Member
    • Jan 2011
    • 103

    #1

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

    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.

    Code:
    <html>
    <title>Pop-up Ad Example</title>
    	<head>
    		<Script language="javascript">
    			function closeWindow(form){
    			window.confirm("Are you sure you want to close this page?");
    	
    			window.close();
    		}
    		</script>
    	</head>
    <body>
    	
    		<form name="myform">
    			<input type="button" name="button" value="Close this Window" onClick="closeWindow(this.form)"></br>
    		</form>
    </body>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    window.close() only works on windows you have previously opened with window.open().

    Comment

    Working...