在我的应用程序中,有一个页面用户可以打开一个弹出窗口。当用户单击注销时,它必须关闭弹出窗口。
我使用静态变量将弹出窗口变量存储在
Global.ts
班
public static QUICKTREND : any;
在打开弹出窗口的函数中,我存储了它
this.quickWin = window.open(URL, 'QuickTrend', 'width=' + w + ',
height=' + h + ', left=' + x + ', top=' + y + ', location=no'+ ', status=no');
Constants.QUICKTREND = this.quickWin;
在logout()函数中,我得到弹出窗口并关闭
if(!isNullOrUndefined(Constants.QUICKTREND)){
let currentIframe = Constants.QUICKTREND;
currentIframe.close();
}
如果我不刷新页面,它就可以正常工作。
但当我刷新页面时,变量quicktrend重置为未定义。
我搜索了在页面刷新时保留变量的解决方案,这是保存到localstorage或sessionstorage的唯一解决方案。但是这样,我就不能保存弹出窗口对象,因为它是dom对象,
Converting circular structure to JSON
错误显示。
localStorage.setItem("currentIframe", this.quickWin);
是否可以将弹出窗口保存到本地存储?
如果页面刷新,如何在注销时关闭弹出窗口?