Home > Article > Web Front-end > How does JS detect whether the window opened by window.open is closed?
During development, we encountered the need to add a mask to the parent window while opening the window to prevent user misoperation, and when the window is closed, the mask of the parent window needs to be removed to facilitate user operation. Therefore, you can use setInterval() to periodically detect whether the open window is closed.
During development, it is necessary to add a mask to the parent window while opening the window to prevent user misoperation, and when the window is closed, it is necessary Remove the mask of the parent window to facilitate user operation.
So you can use setInterval() to periodically detect whether the open window is closed.
If it is detected that the window has been closed, you need to use clearInterval() to terminate monitoring Behavior.
1. Create a new window:
var newWin = window.open(url,name,"height=500,width=1000"); $("body",parent.document).mask("信息编辑中...");
2. Create a monitoring function with a monitoring period of 1 second:
var loop = setInterval(function() { if(newWin .closed) { clearInterval(loop); $("body",parent.document).unmask(); } }, 1000);
The above is the JS introduced by the editor to detect whether the window opened by window.open is closed. I hope it will be helpful to everyone. If you have any questions, please leave me a message. The editor will Reply to everyone promptly!
The above is the detailed content of How does JS detect whether the window opened by window.open is closed?. For more information, please follow other related articles on the PHP Chinese website!