http redirect - Stop page redirection using javascript without warning or asking - Stack Overflow

This answer tells how to stop redirection:<script language="JavaScript" type="textja

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?

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?

Share Improve this question edited May 23, 2017 at 12:33 CommunityBot 11 silver badge asked Oct 28, 2014 at 19:55 тнє Sufiтнє Sufi 6342 gold badges10 silver badges23 bronze badges 2
  • Are you sure that it will be user friendly? Visitor would never be able to leave your page – mandza Commented Oct 28, 2014 at 19:58
  • That did not work on my mind. – тнє Sufi Commented Oct 28, 2014 at 19:59
Add a ment  | 

1 Answer 1

Reset to default 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744438427a4574225.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信