如何在第二次尝试刷新时将页面重定向到另一页面

sss*_*sss 2 javascript jquery browser-refresh

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

在这里我试过但不工作请指导我

Lok*_*h_K 5

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 
}
Run Code Online (Sandbox Code Playgroud)


sac*_*abu 5

Windows onload加载所有内容后加载,其他方法变慢一点是使用document.onload(浏览器兼容性问题)

window.onload = function () {
  window.location = "/allotment";
}
Run Code Online (Sandbox Code Playgroud)


Rob*_*rai 2

下面的代码适合你

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