-1

In a page I have a 'Close' button that when clicked has to close the current browser tab (the tab in which is the page that contain this close button). So I wrote something like this:

<button type="button" class="btn btn-default" style="color: #0F8BB0;" onclick="window.close();">
    Close
</button>

But it doesn't work and the current browser tab is not closed. Why? What am I missing? How can I try to solve this issue?

1
  • You can only close child windows (or tabs) that have been created from the original tab - you cannot close the originator. Commented Nov 10, 2015 at 10:16

1 Answer 1

2

You are doing it correctly, however browsers prevent you from closing a window if your javascript didn't create it.

So basically you can only close a window if you opend that window through javascript.

Also see: window.close and self.close do not close the window in Chrome

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

2 Comments

and there is not any way to force this behavior and close it?
no sorry there is no way around this, because of security reasons/user experience.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.