如何在 window.onbeforeunload 中禁用对话框警报并关闭网站?

How to disable dialog alert and close the website in window.onbeforeunload?

如何在 window.onbeforeunload 中禁用对话框警报并关闭网站?

window.onbeforeunload = function() {
  var isVisible = $('#submitbtn').is(':visible');
  if(isVisible==true){
    return null;
  }else{
    return 'you havent close';
  }

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" />