无法在窗口退出时打开弹出窗口

时间:2013-07-12 15:39:30

标签: jquery

当有人关闭浏览器时,我想打开一个jquery popup loadSound();。但它没有打开弹出窗口。

代码工作:

window.onbeforeunload = function() {
    alert("hello");
}

代码无效:

window.onbeforeunload = function() {
    loadSound();
}

不知道为什么它适用于alert("hello");但不适用于loadSound();

整个代码:

function lightbox(){
    //to adjust popup width adjust here
    $.colorbox({inline:true, href:"#inline_content",onClosed: pauseSound, overlayClose: false});
}

function pauseSound() {
    document.getElementById("notification_sound").pause();
}       
///////////////////pop strts here
function loadSound() {
    lightbox();
    document.getElementById("notification_sound").play();
}  
///////////////popup ends here

window.onbeforeunload = function() {
    loadSound();
}

1 个答案:

答案 0 :(得分:0)

window.onbeforeunload = function() {
    return "hello do you wan to get out?";
}