-1

I'm trying to close the current browsing window in JavaScript. I've tried the following code. It works in Chrome and Safari, but doesn't in Firefox.

var win = window.open('', '_self', '');
win.close();
Bojangles
  • 99,427
  • 50
  • 170
  • 208
Sendil Kumar
  • 1
  • 1
  • 5
  • 1
    possible duplicate of [How to close current tab in a browser window?](http://stackoverflow.com/questions/2076299/how-to-close-current-tab-in-a-browser-window) – Qantas 94 Heavy Jun 04 '15 at 13:15

1 Answers1

-2

You will need JavaScript to do this. Use window.close():

function close_window() {
  if (confirm("Close Window?")) {
   close();
  }
}

HTML:

<a href="#" onclick="close_window();return false;">close</a>
Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
  • 1
    Welcome to [so]. This won't work properly as the `close` method only works for windows opened using JavaScript. Please take the [tour] when you can. Thanks! – Qantas 94 Heavy Jun 04 '15 at 13:12