Link to home
Start Free TrialLog in
Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on

how to disable back button

Hi  ,

how to disable back button . ?

I did below code like this but it goes to previous page and come back ??
function noBack()
{ 

window.history.forward(1);
}
</script>
</head>
<body onload="noBack()" >

Open in new window

SOLUTION
Avatar of Graceful_Penguin
Graceful_Penguin
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@mplungjan - Erm, no you can't.

What you are doing isn't disabling the browsers back button in any way whatsoever. The Back button belongs to the browser and you have no access to it from your page and therefore CANNOT disable it.

@mplungjan jou are not disabling the back button or you are just messing around with the navigation on a specific link.
Words, words... I show how to stop people from going back to the previous page which is what he wants.
No I am not disabling it since you cannot disable it as in "grey it out". You can still mess with it in such ways that users will get annoyed but should not be attempted.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sathish David  Kumar N

ASKER

what is Next page?
<a href="page2.html" onclick="location.replace(this.href); return false">Next page</a>
 
How this code will stop the user to go to the previous screen ??
It won't. It may stop the user going back to a previous page on YOUR site but it will NOT stop the Back button working.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
We implement this in following way:
1. Open the application in a dialog, and all the application runs in that dialog.
2. In this dialog, we don't show the toolbar.
3. We have disabled the shot keys and right click using javascript.
At the end of the day, you can't stop the user using the Back button.  Any solution yoo come up with is going to take a lot of messy boiler-plate code that is only ever going to do half the job and there will be a myriad of ways to circumvent it.

You haven't mentioned specifically why you are trying to stop the user going back, but if you have to resort to it then it will usually suggest a flaw elsewhere in your design.
@dravidnsr: I suggested you to add that meta tag which will tell the browser, not to cache at all. It makes sense also, because if you do not want the user to go back, they why cache that page at first place.

have you tried that?
Not able to understand why are you not responding on the same.
I completely agree with carl_tawn if you have to pull hacks like this to sercumvent intended security features in the browser there is something wrong in your design and that should be fixed not the fact that the user should not go back.
@gurvinder372:
Itried your solution it wont work ?
Blocking a page from caching does not stop it from entering the history. So it is not a solution

Dravidnsr: Please explain us what you NEED and not what you try to do.

If you want to show page 1 and then page 2 and not allow the person to see page 1 again using the back button, put the link in page 1 that I suggested. It will replace page1 in history with page2.

Try This..
Inside HEAD tag
<script type="text/javascript" language="javascript">
            javascript:window.history.forward(1);
    </script>

 
Hi,
This too helps you.. not to display the page on click of back button

Response.Buffer=<SPAN style="COLOR: blue">true;<o:p></o:p>
Response.ExpiresAbsolute=DateTime.Now.AddDays(-1d);
Response.Expires =-1500;
Response.CacheControl = "no-cache";
 if(Session["SessionId"] == null)
    {
      Response.Redirect ("WdetLogin.aspx");
    }
}
That will work faster than waiting for the body onload. HOWEVER it will BREAK the back button so please do not do it.

Also remove the javascript: from the statement
Hi,
The Question is to disable the back button right ?.
I think the IDEA was to prevent the user from going back to a previous page. But not BREAK the back button in the process.

There is often a big difference between what the people really need and what they believe is the way to achieve the goal.

If the only tool you have is a hammer, all problems will start looking like nails.
@mplungjan:
 
where can i put this code
 
<a href="page2.html" onclick="location.replace(this.href); return false">Next page</a>
On the PREVIOUS page - the page you do not want to go back to