[英]javascript confirm dialog box before close browser window
I need to display a confirm dialog box before closing the browser window using javascript or PHP. 我需要在使用javascript或PHP关闭浏览器窗口之前显示确认对话框。 The confirm box should come up when I click the close button of browser;
单击浏览器的关闭按钮时,应出现确认框; otherwise, the dialog should not be displayed.
否则,不应显示该对话框。
Thanks 谢谢
This will display it when closing the browser: 这将在关闭浏览器时显示:
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;
}
Use this code , I used that earlier, I here 使用此代码,我之前使用过,我在这里
<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>
With Jquery: 使用Jquery:
$(window).bind('beforeunload', function(e) {
// Your code and validation
if (confirm) {
return "Are you sure?";
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.