在Chrome模式弹出窗口中关闭(x)按钮之前发出警报

时间:2017-12-19 07:41:43

标签: javascript html css angularjs

我想关闭弹出式模态确认警报,但上面的代码无效。 我还尝试了popupcsd.onbeforeunloadpopupcsd.onUnload但没有工作

var popupcsd = window.open('www.example.com', 'CSD ', 'width=1000, height=800');

    
    var popupcsd =window.open('www.example.com', 'CSD ', 'width=1000, height=800');

    popupcsd.beforeunload = function(){
                    console.log('leaving page'); // Use 'Preserve Log' option in 
    Console
                    alert('alert');
                    return leavingPageText;
                }

我在Angular JS

中使用此代码

2 个答案:

答案 0 :(得分:0)

而不是beforeunload使用onbeforeunload

popupcsd.onbeforeunload = function(){
    console.log('leaving page');                    
    alert('alert');
    return leavingPageText;
}

我尝试了它的工作在我的最后

答案 1 :(得分:0)

您使用的回拨名称错误。它应该如下改变。

 popupcsd.onbeforeunload instead of popupcsd.beforeunload
相关问题