How can we can close the close current tab in a browser window using JavaScript?
As long as the window was created by your JS, then you can call the window.close()
method. If the window wasn’t created by your JS, technically you can’t (although it did used to work for a few arbirary browsers)
Basically the code used to create the window can close the window (or tab in this case), this is how sign in popups work for example. This is safe: the code is not interfering with anything else. But code should not be able to close the window if it did not open it, that would be a security issue.
I think In earlier time it was possible to close the current tab by using the window.close() function
& due to security feature, this syntax has lost its privilege to close the current tab
my first thought was to use the browser api but then you might have to do it for each browser.