-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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

1 Answers1

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

Community
  • 1
  • 1
Dirk-Jan
  • 1,109
  • 10
  • 21