Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

I tried this code, but it is not working.

like image 242
sss Avatar asked Dec 24 '11 05:12

sss


4 Answers

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 
}
like image 74
toxi_code Avatar answered Nov 15 '22 05:11

toxi_code


below code will work for you

function confirmExit()
{
 alert("exiting");
 window.location.href='index.html';
 return true;
}
window.onbeforeunload = confirmExit;
like image 2
Robin Michael Poothurai Avatar answered Nov 15 '22 04:11

Robin Michael Poothurai


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";
}
like image 2
sachin babu Avatar answered Nov 15 '22 03:11

sachin babu


In bbb.jsp file

<script>
    submitFormOkay = false;
    $(document.body).on("click", "a", function() {
        submitFormOkay = true;
    });
    window.onbeforeunload = function(event) {
        event.preventDefault(); 
        if (!submitFormOkay) {
            window.setTimeout(function () { 
                window.location = "index.html";
            }, 0); 
            window.onbeforeunload = null;
        }
    }
</script>

I hope this will help. Cheers!

like image 1
Chandni Soni Avatar answered Nov 15 '22 03:11

Chandni Soni