我想在用户关闭弹出窗口时显示警告

时间:2014-08-15 09:38:20

标签: javascript php

我想要显示一个弹出窗口(Google,Twitter等),当用户关闭该对话框时,我想要显示警告" bye",但该警报不会出现:

<script>
var openDialog = function(uri, name, options, closeCallback) {
var win = window.open(uri, name, options);
var interval = window.setInterval(function() {
    try {
        if (win == null || win.closed) {
            window.clearInterval(interval);
            closeCallback(win);
        }
    }
    catch (e) {
    }
}, 1000);
return win;
};
var test = function() {
alert("bye");
};

openDialog("//google.com", "popup", "scrollbars=no", "test");
</script>

2 个答案:

答案 0 :(得分:3)

更改此代码

openDialog("//google.com", "popup", "scrollbars=no", "test");

与此:

openDialog("//google.com", "popup", "scrollbars=no", test);

演示:http://jsfiddle.net/3on19uak/

答案 1 :(得分:0)

这一行:

 openDialog("//google.com", "popup", "scrollbars=no", "test");

应阅读:

 openDialog("//google.com", "popup", "scrollbars=no", test);

如果你想要,你也可以这样做:

 openDialog("//google.com", "popup", "scrollbars=no", function(e){
    alert("bye");
 });