+ 2
Is this code valid to close a window?
function quitBox(cmd) { if (cmd== 'quit' ) { open(location, '_self' ).close } return false; } Explain further...
1 Antwort
+ 1
I haven't tried it out but this code wouldn't work. open and close only work like this:
let newWindow = window.open(url, windowName, [windowFeature]);
newWindow.close();
With this you would open a new window and call the method close() on it. However there is the problem that the browser doesn't allow you to close windows you didn't create. This means that in many cases such code would lead to an error: "Scripts may not close windows that were not opened by script."
For a better understanding of the window methods I would recommend using the MDN web docs on open() and close().
open:
https://developer.mozilla.org/en-US/docs/Web/API/Window/open
close:
https://developer.mozilla.org/en-US/docs/Web/API/Window/close