Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm having a problem always when I'm trying to close a window through the window.close() method of the Javascript, while the browser displays the below message on the console:

"Scripts may close only the windows that were opened by it." 

This occurs in every part of the page. I can run this directly of a link, button, or a script, but this message always are displayed.

I'm tried to replace the window.close(); method for the functions (or variants of these) below, but nothing happened again:

window.open('', '_self', ''); window.close(); 
like image 437
mayconfsbrito Avatar asked Sep 19 '14 15:09

mayconfsbrito


People also ask

How do you fix Scripts may close only the windows that were opened by them?

Scripts may close only the windows that were opened by it. A workaround now is redirect user to another page rather than close the window, you could redirect user to a notification page to show "The items has been closed successfully" using window. location. href="PageUrl".

Why window close () is not working in Chrome?

close() function won't work due to Chrome Security feature which not allow close the current window by JavaScript window. close(). If you check the message in the Chrome Developer Tool Console, you will find such message: Scripts may close only the windows that were opened by it.

How do I close a browser window in HTML?

window. top. close(); this will close the current tab for you.

How do I close a window using JavaScript?

Simply call window. close() and it will close the current window. If it doesn't work... it should always work.


1 Answers

Error messages don't get any clearer than this:

"Scripts may close only the windows that were opened by it." 

If your script did not initiate opening the window (with something like window.open), then the script in that window is not allowed to close it. Its a security to prevent a website taking control of your browser and closing windows.

like image 143
somethinghere Avatar answered Oct 09 '22 03:10

somethinghere