Solved

Disable back button in Browser

Posted on 2001-08-05
29
393 Views
Last Modified: 2008-02-26
hi,
 I need to disable the back button in browswer for security. Is it possible.. please guide me
TIA
0
Comment
Question by:kousis
  • 11
  • 6
  • 3
  • +5
29 Comments
 
LVL 1

Expert Comment

by:rumblefiz
ID: 6353978
as far as i know it is not possible to disable the back button. if it is critical that a user not go back to a page, i use javascript to remove the page from history. that way when the user presses back, they go to the page before the page you dont want them to see. example:

page1.htm
<html>
<head>
   <title>Page 1</title>
   <script language="javascript">
      location.replace("/index.html");
   </script>
</head>
<body>
All your other stuff
</body>
</html>

now when someone loads page1.htm for the first time, they will see whatever you have in the body. when they submit or go to another page, when they press the back button, index.html will load instead. this does not make the entry in the history list disappear if you click on go | etc... but it does replace the doc with the one you specify. if you dont specify one, i think it may just remove it and they will go back to the page they were on before they loaded page1.html.

this worked for me and it may work for you. may not though.

- rumblefiz
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6354465
It is not possible to do that.

Read this for some workarounds of it.
http://www.4guysfromrolla.com/webtech/111500-1.shtml
http://www.4guysfromrolla.com/webtech/111500-1.2.shtml

hongjun
0
 
LVL 33

Accepted Solution

by:
hongjun earned 50 total points
ID: 6354472
More information.


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");

Replace method will make sure that the history collections will be cleared and thus Back button will have no effect.


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");

hongjun
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6354717
You can't do it directly, but her's a work around:

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

or this:

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

this way you disable the ability to move backwards.


0
 
LVL 33

Expert Comment

by:hongjun
ID: 6354733
In conclusion, you cannot really disable the back button. You just have to resort to using workarounds. Combine mine and Silvers5's and you will get what you wanted.

hongjun
0
 

Expert Comment

by:pack
ID: 6355599
<script language="JavaScript">
<!--
  javascript:window.history.forward(1);
//-->
</script>
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6355768
pack,

What is the difference between your

<script language="JavaScript">
<!--
 javascript:window.history.forward(1);
//-->
</script>

and Silvers5's

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


hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6355771
kousis,
please reject pack's answer and consider mine or Silvers5's.

hongjun
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6358882
or split for both
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6362255
OK
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6362671
But first of all the questionner got to reply.

hongjun
0
 

Author Comment

by:kousis
ID: 6363796
while using location.replace() page is getting refreshed for each sec. i don't know where the problem is. could u pls suggest me
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6364015
Why don't you use document.replace instead? First of all, reject his answer.

hongjun
0
 

Author Comment

by:kousis
ID: 6364277
while using location.replace() page is getting refreshed for each sec. i don't know where the problem is. could u pls suggest me
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 3

Expert Comment

by:CyberSoft
ID: 6368083
Pack - since you're new to Experts-Exchange I would suggest you carefully read through the section regarding questions and answering questions here : http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp

In brief. Do not post your comment as an answer unless it completely provides a solution to the person posting the question and that it has NOT already been suggested by another user as a comment.

Ideally all users should only post comments as it allows the person who posted the question to select the correct person for points awarding. This also keeps the question in the un-answered questions section so that other experts can see it and post a reply. Otherwise it gets moved to the Locked questions section.

In answer to your question pretty much everyone has given the same answer as there is no way of really "disabling" the back button except for resorting to work-arounds. If you don't want users to use browser navigation other than that which you provide on your site then I'd suggest opening your site in a toolbar-less window as well as disabling the right click. Then you MUST however make sure that your navigation is 100% adequate and easy to use.

Regards,
CyberSoft
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6375924
pack I am rejecting your answer as it duplicates comments proposed by other members.

Lunchy
Friendly Neighbourhood Community Support Moderator

0
 

Author Comment

by:kousis
ID: 6375988
document.replace() is giving runtime error
"object doesn't support this property"
0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6376016
Should be location.replace('filename.html') NOT document.replace('filename.html')

Regards,
CyberSoft
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6376017
Try
window.replace("index.html");

hongjun
0
 

Author Comment

by:kousis
ID: 6377025
like rumblefiz suggested, i am giving this window.replace in head, but it's printing the page which i am specified in the url first not the page which i gave in the <body>

so suggest where i ahve to use the code.
TIA
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6377409
Try this

first_page.asp
=============
Click <a href=javascript:window.replace("second_page.asp")>here</a>

hongjun
0
 

Author Comment

by:kousis
ID: 6377933
It is working while i am giving it in onClick()
In my case.
I got 2 frames
in one frame i have logout option. After clicking the logout option it goes to main screen then if i click back in the browser it goes to the prevoius page which i don't want to. I want to redirect to some other page.
Hope u understand my query and clear my doubt

TIA
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6395160
<ping>
0
 

Author Comment

by:kousis
ID: 6397822
Lunchy
what is that mean?
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6397918
Sorry kousis, I didn't realize I was getting notifications on this question so I posted a ping comment to make sure I was getting them.
0
 
LVL 20

Expert Comment

by:Silvers5
ID: 6405151
try

document.location.replace("url")
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6772154
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6773298
any progresses?

hongjun
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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

24 Experts available now in Live!

Get 1:1 Help Now