簡體   English   中英

關閉瀏覽器窗口之前的javascript確認對話框

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM