2010-12-29 12 views
-1

イベントアンロードでページの更新を停止するにはどうすればよいですか?あなたは文字列を返すと、このように、直接結合する必要がイベント「アンロード」のページを更新しないでください

$(window).unload(function(){ 
    if(confirm('Do you really want to exit the survey without completing it? Your data will be deleted.')){ 
     // This does not currently work in the method 
     // onbeforeunload which took Nick Craver 
      $.ajax({ 
       url: 'db_sotr_file.anket_my.ajax_remove_anketa', 
       dataType: 'html', 
       success: function(){ 
        $.cookie('refresh_page', null); 
        $.cookie('hashid', null); 
        $.cookie('sessionid', null); 
       } 
      });   // This moment is the most important 

     // page the refresh 
     return true; 
    } 
    // don't refresh the page 
    return false; 
}); 
+1

*完全に*質問を変更したときには必ずコメントしてください。 –

答えて

1

:信頼性が高いことが

window.onbeforeunload = function() { 
    return 'Do you really want to exit the survey without completing it? Your data will be deleted.'; 
}; 

、あなたの代わりにonbeforeunloadを必要とする...とjQueryは、この正しくクロスブラウザに結合しませんイベントハンドラを直接設定する方がよいでしょう。いくつかのブラウザはそこにロジックを許可しませんreturn "string"以上のページを停止する限り...ので、クロスブラウザ(主にここにFirefox)を動作するようにその形式を使用します。

関連する問題