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

Rory McCrossan
  • 319,460
  • 37
  • 290
  • 318
AndreaNobili
  • 38,251
  • 94
  • 277
  • 514

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,089
  • 10
  • 20