Home > Web Front-end > JS Tutorial > How does JS detect whether the window opened by window.open is closed?

How does JS detect whether the window opened by window.open is closed?

零下一度
Release: 2018-05-29 11:00:25
Original
3434 people have browsed it

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("信息编辑中...");
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template