javascript – Close tab Mozilla, IE, Chrome


I'm trying to close a tab on my site, I've already tried using the following commands:

  •'','_self',''); window.close();
  • window.close()
  • self.close()
  • var win ="","_self"); win.close();
  • window.parent.close();
  •'','_self',''); top.close();

Many of these work fine in Chrome and IE, but in Mozilla it doesn't work, it only works if I run the command in the console in a new tab, but not in my site's tab.

Does anyone have any tips?


Hello, to execute window.close() the action must come from an event (I always use the click), because I don't know if it works for other events.

So if you do:

document.getElementById('btn').addEventListener('click', function()
}, false);

The tab will be closed, this is valid for tabs on your site, in case of popup there is no such problem as long as the popup was opened from your site! Popup example:

var popup ="");
Scroll to Top