The front-end page browser creates a new window, how does the front-end page monitor the closing status of the new window

The front-end page browser creates a new window, how does the front-end page monitor the closing status of the new window

Application scenario: Suppose I need to monitor the opened page. When it is closed, I will assume that the data has been modified on the page. Then after I monitor it is closed, the program will automatically refresh the data to ensure that the data that the user sees is the latest.

Use the front-end timer to constantly check whether the browser window object is closed, so as to achieve the desired function


const  win = window.open(this.$ruoter.resolve({
    
    path: ‘xxx/xxx’,query:{
    
    }).href, '_blank')
const loop = setInterval(()=>{
    
    
	if(win && win.closed) {
    
    
	this.更新数据()
	clearInterval(loop)
}500)

Guess you like

Origin blog.csdn.net/weixin_43865196/article/details/127439051