0
我有一個彈出窗口,如果我刷新它失去unbeforeunload回調。將unbeforeunload方法綁定到刷新彈出窗口的正確方法是什麼?將unbeforeunload方法再次綁定到刷新的彈出窗口
var url = ...,
title = ...,
params = [
"height=" + screen.height,
"width=" + screen.width,
"fullscreen=yes",
"resizable=yes",
"scrollbars=yes",
"toolbar=yes",
"menubar=yes",
"location=yes"
].join(",");
var popup = window.open(url, title, params),
onbeforeunloadCallback = function (e) {
var isRefresh = this.opener.title == undefined;
if (isRefresh) {
// It doesn't work for second refresh
// so what am I doing wrong ?
console.log("It is refreshing");
popup.onbeforeunload = onbeforeunloadCallback;
}
};
popup.onbeforeunload = onbeforeunloadCallback;