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.



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 you can close it with window.close().


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.


Found a one-liner that works in Chrome 66 from:

TLDR: tricks the browser into believing JavaScirpt opened the current tab/window'', '_parent', '').close();

So for completeness

<input type="button" name="close" value="close" onclick="window.close();">

Though let it also be noted that readers may want to place this into a function that fingerprints which browsers require such trickery, because Firefox 59 doesn't work with the above.


You can use below JavaScript.'','_self').close();

In a HTML you can use below code

<a href="javascript:close_window();">close</a>

I have tried this in Chrome 61 and IE11 it is working fine. But this is not working with Firefox 57. In Firefox we can only close, windows which opened using below command.

Try this:

    var myWindow ="ANYURL", "MyWindowName", "width=700,height=700");

This worked for me in some cases in Google Chrome 50. It does not seem to work when put inside a javascript function, though.


Use this:'', '_self');

This only works in chrome; it is a bug. It will be fixed in the future, so use this hacky solution with this in mind.


Try this:'', '_self').close();


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.