-2

How do I close a browser window with HTML code?

all browser compatibality

window.close(); not working

  • 1
    possible duplicate of [JavaScript/ jquery for Closing Browser FireFox / chrome / IE](http://stackoverflow.com/questions/7529641/javascript-jquery-for-closing-browser-firefox-chrome-ie) – Bhushan Kawadkar Sep 01 '15 at 10:40
  • "window.close(); not working" - You mean using Firefox? Might be this could help you: [window.close(), self.close() not working on mozilla firefox](http://stackoverflow.com/questions/3465191/window-close-self-close-not-working-on-mozilla-firefox) – fab Sep 01 '15 at 10:42

4 Answers4

0

See the second reply below for a discussion on when the window can be closed:

window.close and self.close do not close the window in Chrome

Community
  • 1
  • 1
BobbyTables
  • 4,481
  • 1
  • 31
  • 39
0

I'm quoting the answer of this question

Scripts are not allowed to close a window that a user opened. This is considered a security risk. Though it isn't in any standard, all browser vendors follow this (Mozilla docs). If this happens in some browsers, it's a security bug that (ideally) gets patched very quickly.

Community
  • 1
  • 1
Tom Doodler
  • 1,471
  • 2
  • 15
  • 41
0
Use window.close() for close the window or tab in javascript

$(".close-btn").click(function(event) {
    window.close();
});
  • Welcome to Stack Overflow! Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working and seems self explanatory) usually wont help the OP to understand their problem. – SuperBiasedMan Sep 01 '15 at 11:20
-1

Try window.top.close(); or window.close();

Nishant
  • 358
  • 2
  • 5
  • 11