I tried to close a window using window.close() when user clicks on cancel button, but window not closing.I am getting the following message in console
scripts may close only the windows that were opened by it.
I tried to close a window using window.close() when user clicks on cancel button, but window not closing.I am getting the following message in console
scripts may close only the windows that were opened by it.
this question has already been answered HERE
This method window.close()
is only allowed to be called for windows that were opened by a script using the window.open()
method.
It's a security to prevent a website taking control of your browser and closing windows.
You can try this. As it has been used here Reference Link
function CloseWithWindowOpenTrick()
{
var objWindow = window.open(location.href, "_self");
objWindow.close();
}