2

This answer tells how to stop redirection:

<script language="JavaScript" type="text/javascript">
    //<![CDATA[
        window.onbeforeunload = function(){
            return 'Are you sure you want to leave?';
        };
    //]]>
</script>

This codes works, but asks an user whether to stay on the page or redirect. Can the redirect be stopped without any type of alert or asking?

Community
  • 1
  • 1
тнє Sufi
  • 574
  • 2
  • 9
  • 23

1 Answers1

5

No, it cannot. If that were allowed, a malicious page could permanently prevent someone from leaving it. Therefore, the user must be allowed to decide.

If you are leaving from an event handler though, you can usually return false to stop it from happening.

Scimonster
  • 32,893
  • 9
  • 77
  • 89