2

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();" />

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
for the user: yes (ctrl+w, alt+f4, click the close box etc.) :-) for you: no

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.