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.
window. top. close(); this will close the current tab for you.
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()
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With