我有一个简单的项目,但我是javascript的新手, 我需要的是当用户离开页面时强制鼠标点击对话框
怎么做?
答案 0 :(得分:1)
你需要使用这个事件,附带的“onbeforeunload”有窗口:
答案 1 :(得分:0)
查看“卸载”事件;)
在卸载电话中,您只需要拨打
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;