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
1 Answer
Reset to default 5No, 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条)