Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close Current Tab

I have a close link on my web page. I would like to function it to close the current tab when click it. I have written

<a href="#" onclick = "javascript:self.close();">close</a> 

The above code seems to be working well in Internet Explorer. But it is not working in Mozilla Firefox and Google Chrome. Please help me to resolve this.

like image 543
Vinod Kumar Avatar asked Jan 17 '13 06:01

Vinod Kumar


People also ask

How do I close the current tab in HTML?

window. top. close(); this will close the current tab for you.


2 Answers

You can only close windows/tabs that you create yourself. That is, you cannot programmatically close a window/tab that the user creates.

For example, if you create a window with window.open() you can close it with window.close().

like image 159
Brian Ustas Avatar answered Oct 05 '22 08:10

Brian Ustas


As of Chrome 46, a simple onclick=window.close() does the trick. This only closes the tab, and not the entire browser, if multiple tabs are opened.

like image 35
Adam M Avatar answered Oct 05 '22 08:10

Adam M