2010-06-15 63 views
0

我有一個基本功能來提醒用戶刷新,瀏覽器後退按鈕(除了提交按鈕)或單擊鏈接時,他們將失去表單數據從表單嚮導。jConfirm和onbeforeunload

<script type="text/javascript"> 
var okToSubmit = false; 
window.onbeforeunload = function() { 
    document.getElementById('Register').onclick = function() { okToSubmit = true; }; 
    if(!okToSubmit) return "Using the browsers back button will cause you to lose all form data. Please use the Next and Back buttons on the form"; 
}; 
</script> 

即時通訊使用jAlert插件的警報,並希望使用jConfirm上述功能。當我在「返回」後添加jConfirm時,它可以工作...一秒鐘。它會彈出警告,然後頁面刷新並且對話框消失。有誰知道如何解決這一問題?

回答

0

我相信你還是需要return false;,否則卸載動作仍然會發生。我對這個插件並不熟悉,但是嘗試類似於:

// your code 
if(!okToSubmit) 
{ 
    alert("Using the browsers back button will cause you to lose all form data. Please use the Next and Back buttons on the form"); 
    return false; 
} 
// the rest of your code 
+0

如果插件希望返回true或者無論您的響應是什麼,那麼忽略此答案。 – hookedonwinter 2010-06-15 17:55:08

+0

thx生病了,這個「警報」的工作和確認對話一樣嗎? – 2010-06-15 18:09:35

+0

nope。只提醒警報。確認提供了該選項。所以你可以把它切換到'var whatTheySaid = confirm(「你準備好了嗎?」)然後根據返回結果(true或false)來做。 – hookedonwinter 2010-06-15 18:11:41