How to close current tab using javascript?

I suggest this little function JS, it works on Chrome 54.0.2840.99

function closeWin() { 
    window.top.close();
}
setTimeout(function(){ 
    closeWin()
}, 1000);

This seems to work from a previous thread: https://stackoverflow.com/a/18776480/3642027

However, from my testing, it only works if it's a fresh link opened with target="_blank".


It is possible. I searched the whole internet for this, but once when i took one of Microsoft's survey, I finally got the answer.

try this:

window.top.close();

this will close the current tab for you.


Since the actual answer is obsolete because of security issues the closest working solution i found today is

open(location, '_self').close();

I also recommend to check this thread where i got the code from its many authors: How to close current tab in a browser window?