前端页面浏览器新建一个窗口,该前端页面如何监听该新窗口的关闭状态

前端页面浏览器新建一个窗口,该前端页面如何监听该新窗口的关闭状态

应用场景:假设我需要监听打开的页面,当他关闭时,我就默认该页面已经对数据做了修改,那么我监听它关闭后,程序自动刷新数据,保证用户看到的数据是最新的。

使用前端定时器,不断的查看浏览器窗口对象是否被关闭,从而实现想要的功能


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

猜你喜欢

转载自blog.csdn.net/weixin_43865196/article/details/127439051