Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What are the best scripts to prevent user to redirect or refresh or press back button on a web page?

<p>want to <strong>prevent</strong> a logged user from pressing <strong>back button</strong> or <strong>reload</strong> the page or not to <strong>redirect</strong> any way from the existing page. May user's logging session will expire if he try to do any one of above circumstances.</p>

user-image
Question added by Suman Rajbhar , System Analyst , Sys Dev Limited
Date Posted: 2014/10/29
Deleted user
by Deleted user

Use this on window on load event:

<body onunload="javascript:history.go(1)">

 

use jQuery to prevent page refresh .

function disableF5(e) { if ((e.which || e.keyCode) ==116) e.preventDefault(); };

// To disable f5

    /* jQuery <1.7 */

$(document).bind("keydown", disableF5);

/* OR jQuery >=1.7 */

$(document).on("keydown", disableF5);

 

// To re-enable f5

    /* jQuery <1.7 */

$(document).unbind("keydown", disableF5);

/* OR jQuery >=1.7 */

$(document).off("keydown", disableF5);

 

More Questions Like This