Close Mozilla tab, IE, Chrome

6

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

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

Many of these work right in Chrome and IE, but in Mozilla does not work, it only works if you run the command in the console in a new tab, but not in the tab of my site.

Does anyone have any tips?

    
asked by anonymous 28.05.2014 / 16:08

4 answers

2

Hello, to run window.close () the action should come from an event (I always use the click), because I do not know if it works for other events.

So, if you do:

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

The flap will be closed, this is valid for your site's tabs, in the case of popup there is no such issue as long as the popup has been opened from your site! Popup example:

var popup = window.open("http://www.teste.com.br");
popup.close();
    
30.05.2014 / 01:10
1

Try to do this:

function tabClose() {
  var tab = window.open("","_self");
  tab.close();
}

I do not use IE, but in Chrome and Firefox, it solves your problem, maybe in IE too, but I could not test it.

    
29.05.2014 / 23:43
1

So it worked in chrome and IE. The "_blank" and "_self" options do not resolve, use "_top". Only the open tab will be closed, if it is the last tab the browser closes!

function tabClose() {
  var tab = window.open(window.location,"_top");
  tab.close();
}
    
29.09.2015 / 13:37
1

I encountered the same problem and solved using:

window.frames.closewindow();

This is because I work with a frame-based system, so I did not test with another type of system. It's worth a try.

    
11.04.2016 / 23:50