views:

35

answers:

1

I open a new window and would like to give the user the option of closing the window using a button. I thought window.close() would work, but nothing happens. Below is a copy of my code.

<script type="text/javascript" language="javascript">
function CloseWindow() {
    //window.open('', '_self', '');
    window.close();
}
</script>
....
<input type="button" value="Close Window" onclick="CloseWindow();" />
+3  A: 

window.close() only works in a window that was opened via javascript (a popup)

seanizer
Thanks :), so is there another way to close the window?
Ask the user nicely to close the window themselves - they opened it. window.close() used to work for all windows, but this feature was abused, so it is no longer enabled for windows which weren't created by JavaScript.
Pete Kirkham
for the user: yes (ctrl+w, alt+f4, click the close box etc.) :-) for you: no
seanizer