Solved

disable back button

Posted on 2001-07-06
6
300 Views
Last Modified: 2006-11-17
I'm looking for a script that will disable the Browsers back button for a single page. It will be for IE5.0 and higher only...anyone have one?
0
Comment
Question by:jgla
6 Comments
 
LVL 7

Accepted Solution

by:
daniel_c earned 88 total points
ID: 6261012
Put this between your <head> and </head> tags.

<script>
<!--
if (history.length > 0) {
  history.go(+1);
}
//-->

</script>

0
 
LVL 2

Expert Comment

by:Ginger_Ed
ID: 6261045
also if you are loading the page yourself (from a link or something) then instead of having a normal link or using window.location.href = "http://wahatever.com/page.htm" use window.location.replace("Http://www.whatever.com/page.htm") and the page will not be put into the history list so a user can never get back to it.


ed
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6261432
There's really no way to do this. Even if there's a way, you should not do it because any users who
surf your site find that he cannot get out of your site once he is in it will never ever wish to visit
it again.



Replace Method
================
document.replace("your_page.htm");



A second method is to make Back button invisible. However, this does not solve the problem totally because
users can always use Backspace to do a back.

Hide Back Button
===================
window.open("your_page.htm","","height=300,width=500,resizable=0,scrollbars=1");




History Trick
===============
<SCRIPT LANGUAGE=javascript>
{
var Backlen=history.length;
history.go(-Backlen);
top.window.location.href ="YourPage.asp";
}
</SCRIPT>

or this:

<body OnLoad="window.history.forward();">


Read more on this (Server side also here)
=====================================
http://www.4guysfromrolla.com/webtech/111500-1.shtml
http://www.4guysfromrolla.com/webtech/111500-1.2.shtml


hongjun
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:hongjun
ID: 6261433
Though there's no way to disable the back button, there's some tricks as described by me above.

hongjun
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6262373
Open a new window

<a href="mypage.htm" onClick="window.open(this.href);return false;">
0
 

Author Comment

by:jgla
ID: 6265664
Perfect. I should have thought of that! But I guess that's why I asked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
count download link and run update query 9 57
how can display objects ? 3 24
Download a website to hdd 2 51
Detect change of Select using JavaScript Only 12 48
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now