强制鼠标单击弹出窗口

时间:2011-07-15 12:42:41

标签: javascript

我有一个简单的项目,但我是javascript的新手, 我需要的是当用户离开页面时强制鼠标点击对话框

Confirm dialog on leaving page

怎么做?

2 个答案:

答案 0 :(得分:1)

你需要使用这个事件,附带的“onbeforeunload”有窗口:

https://developer.mozilla.org/en/DOM/window.onbeforeunload

答案 1 :(得分:0)

查看“卸载”事件;)

http://jsfiddle.net/K5FzG/1/

在卸载电话中,您只需要拨打

confirm('Are you sure ?');

或者像评论“onbeforeunload”中所说的,如果你想在页面中使用对象

function goodbye(e) {
    if(!e) e = window.event;
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog

    //e.stopPropagation works in Firefox.
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
}
window.onbeforeunload=goodbye;