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();
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".
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.
window. top. close(); this will close the current tab for you.
Simply call window. close() and it will close the current window. If it doesn't work... it should always work.
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.
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