[英]javascript confirm dialog box before close browser window
我需要在使用javascript或PHP关闭浏览器窗口之前显示确认对话框。 单击浏览器的关闭按钮时,应出现确认框; 否则,不应显示该对话框。
谢谢
这将在关闭浏览器时显示:
window.onbeforeunload = function (event) {
var message = 'Sure you want to leave?';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
}
使用此代码,我之前使用过,我在这里
<html>
<head>
<title>.:I 0wn U:.</title>
<script language="JavaScript">
<!--
window.onbeforeunload = bunload;
function bunload(){
dontleave="Are you sure you want to leave?";
return dontleave;
}
//-->
</script>
</head>
<body>
Please stay on this page!
</body>
</html>
使用Jquery:
$(window).bind('beforeunload', function(e) {
// Your code and validation
if (confirm) {
return "Are you sure?";
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.