How to redirect a page to another page when refresh at second attempt

佐手、 提交于 2019-12-07 20:54:51

问题


<script language="JavaScript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
   alert("");window.location="index.html";
  }
</script>

Here i tried but not working please guide me


回答1:


In bbb.jsp:

window.onbeforeunload = function() { 
    window.setTimeout(function () { 
        window.location = 'AAA.jsp';
    }, 0); 
    window.onbeforeunload = null; // necessary to prevent infinite loop, that kills your browser 
}



回答2:


Windows onload loads after all the content is loaded, little bit slow other workaround is to use document.onload(Browser compatibility issue)

window.onload = function () {
  window.location = "/allotment";
}



回答3:


below code will work for you

function confirmExit()
{
 alert("exiting");
 window.location.href='index.html';
 return true;
}
window.onbeforeunload = confirmExit;



回答4:


This has worked for me. Not the second attempt part, but changing URL after showing the popup. If you hit cancel, the function is not ran. If you click "Reload", the function is called and you will be redirected.

$(window).on('beforeunload', function() {
  $(window).on('unload', function() {
    window.location.href = 'index.html';
  });

  return 'Not an empty string';
});


来源:https://stackoverflow.com/questions/8622892/how-to-redirect-a-page-to-another-page-when-refresh-at-second-attempt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!