Window.Close and Self.Close Do Not Close the Window in Chrome

self.close() or Window.close() not working on Chrome and Firefox

You simply can not close the window by script due to security reasons on chrome and firefox. But there is a workaround posted here.
That works on chrome 40 and latest version as I have tested.

chrome closing of opened window

Javascript - window.close, self.close, parent.close, none works to close window, tab in Google Chrome

This is a security feature installed into chrome a long time ago.

In order for the window.close() function to be used:

The close() method on Window objects should, if all the following conditions are met, close the browsing context A:

  • The corresponding browsing context A is script-closable.

  • The browsing context of the incumbent script is familiar with the browsing context A

  • The browsing context of the incumbent script is allowed to navigate the browsing context A.


A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a browsing context whose session history contains only one Document.

So you essentially cannot use javascript to close a window that wasn't opened by the javascript within the page.

Read more here.

My suggestion would be to redirect your visitors to another page.

Issue with window.close and chrome

I know this question is old, but I ran into the same problem. This worked for me:

window.open('', '_self', ''); //bug fix
window.close();

window.close() doesn't work - Scripts may close only the windows that were opened by it

I searched for many pages of the web through of the Google and here on the Stack Overflow, but nothing suggested resolved my problem.

After many attempts, I've changed my way of testing that controller. Then I have discovered that the problem occurs always when I reopened the page through of the Ctrl + Shift + T shortcut in Chrome. So the page ran, but without a parent window reference, and because this can't be closed.

javascript self.close() in chrome

Under normal circumstances, JavaScript can only close a window that was opened by JavaScript. While certain "hacks" may exist involving window.opener or "opening" a new window in the current tab, they are unreliable because they are bypassing a security thing.

In any case, window.close() should either close the window (if it was opened by JavaScript), or pop up a confirmation asking if the user wants to allow the page to be closed.

How to I use inspect element to close the window without it having to open it too?

Looks like it’s not.

See the documentation:

This method can only be called on windows that were opened by a script using the Window.open() method. If the window was not opened by a script, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.

See also window.close and self.close do not close the window in Chrome.



Related Topics



Leave a reply



Submit