Is this code valid to close a window? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is this code valid to close a window?

function quitBox(cmd) { if (cmd== 'quit' ) { open(location, '_self' ).close } return false; } Explain further...

19th Dec 2019, 2:00 PM
Alfred Juma
Alfred Juma - avatar
1 Answer
+ 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
20th Dec 2019, 11:13 AM
e90d0e_red
e90d0e_red - avatar