我正在使用javascript在弹出窗口上打开YouTube视频。我使用以下代码
var myWindow;
$("#nextview").click(function() {
var vidurl = 'www.youtube.com';
myWindow = window.open(vidurl, "popupWindow", "width=600, height=400, scrollbars=yes");
//counter(myWindow,refreshIntervalId);
});
现在我想在用户关闭此弹出窗口时显示消息。
我尝试了什么
myWindow.addEventListener("beforeunload", function(event) {
event.returnValue = "Write something clever here..";
});
获取错误
Uncaught TypeError: Cannot read property 'addEventListener' of undefined
答案 0 :(得分:0)
试试这个
var myWindow;
$("#nextview").click(function() {
var vidurl = 'www.youtube.com';
myWindow = window.open(vidurl, "popupWindow", "width=600, height=400, scrollbars=yes");
//counter(myWindow,refreshIntervalId);
myWindow.onbeforeunload = function(){
//some code like
alert("closed");
}
});
这也能够让窗户靠近。