Page 1 of 1

Disable back button in browser

Posted: Mon Dec 15, 2008 5:08 am
by sanju
Hi all,

I am doing a online exam application. I want t ot disable the back option.. in browser or backspase button.. etc how can I accomplish that .can any one help??

Regards
Sanju

Re: Disable back button in browser

Posted: Mon Dec 15, 2008 5:19 am
by silenceghost
I used to do serverside validation for disabling the back button in the browser by setting
$_SESSION['var'] on top of the code

if this var is set
then forward the page or redirect to the forward page
$_SESSION['VAR']=true;

NOTE:while redirecting make sure you have preserved you get and post variable
if page is refreshed then it will not work because var is being already set you have to avoid being refresh rest are validation

Code: Select all

 
There are client side validation also for which you can use but i don't simply like that
function func1()
{
  setTimeout("func2()", 10);
}
 
function func2()
{
  try {
    history.forward();
  } catch (e) {
  }
  setTimeout("func2()", 400);
}
 
call func1 on onLoad.
I hope that if there was some method to clear the histroy.back()

Re: Disable back button in browser

Posted: Mon Dec 15, 2008 10:46 am
by pickle
You can't disable the back button. You can open a new window that doesn't have a back button, but there are other ways to go back. If you're doing any server-side checks, make sure the client is actually requesting a new page every time by turning of caching. Otherwise, the client will just load the page from their cache.