2016-12-06 4 views

答えて

0

return undefined;window.onbeforeunload

デモしながら、ダイアログを防ぐために: - 実際に私が戻る前に関数を呼び出している...

window.onbeforeunload = function(e) { 
 
    var isVisible = $('#submitbtn').is(':visible'); 
 
    if (isVisible == true) { 
 
    $(window).unbind(); 
 
    return undefined; 
 
    //is there any way to disable dialog alert and close the website?? 
 
    } else { 
 
    return 'you havent close'; 
 
    } 
 
}; 
 
$('#hidebtn').on("click",function(){ 
 
    $('#submitbtn').toggle(); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<a href="httpp://google.com">Leave page</a> 
 
<input type="button" id="submitbtn" value="You will not get the dialog untill i am visible" /> 
 
<input type="button" id="hidebtn" value="hide/show" />

+0

あなたの迅速な返事に感謝をヌル;私がそれを未定義に戻すように変更した場合。それはその機能を実行しません...... –

+0

は、ユーザーがウィンドウを閉じて、ダイアログやアラートなしで何かを実行する方法はありますか? –

+0

はい、 'return undefined;'の前に関数を呼び出すことはできますが、確認や警告は含めないでください。それは制限だよ – jafarbtech

関連する問題