MrM
MrM

Reputation: 21999

How do I close a window using a button (window.close() doesnt work)?

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

Upvotes: 2

Views: 468

Answers (1)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 298898

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

Upvotes: 3

Related Questions