Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Disable back button in Browser

hi,
 I need to disable the back button in browswer for security. Is it possible.. please guide me
TIA
0
kousis
Asked:
kousis
  • 11
  • 6
  • 3
  • +5
1 Solution
 
rumblefizCommented:
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
 
hongjunCommented:
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
 
hongjunCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Michel SakrCommented:
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
 
hongjunCommented:
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
 
packCommented:
<script language="JavaScript">
<!--
  javascript:window.history.forward(1);
//-->
</script>
0
 
hongjunCommented:
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
 
hongjunCommented:
kousis,
please reject pack's answer and consider mine or Silvers5's.

hongjun
0
 
Michel SakrCommented:
or split for both
0
 
hongjunCommented:
OK
0
 
hongjunCommented:
But first of all the questionner got to reply.

hongjun
0
 
kousisAuthor Commented:
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
 
hongjunCommented:
Why don't you use document.replace instead? First of all, reject his answer.

hongjun
0
 
kousisAuthor Commented:
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
 
CyberSoftCommented:
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
 
LunchyCommented:
pack I am rejecting your answer as it duplicates comments proposed by other members.

Lunchy
Friendly Neighbourhood Community Support Moderator

0
 
kousisAuthor Commented:
document.replace() is giving runtime error
"object doesn't support this property"
0
 
CyberSoftCommented:
Should be location.replace('filename.html') NOT document.replace('filename.html')

Regards,
CyberSoft
0
 
hongjunCommented:
Try
window.replace("index.html");

hongjun
0
 
kousisAuthor Commented:
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
 
hongjunCommented:
Try this

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

hongjun
0
 
kousisAuthor Commented:
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
 
LunchyCommented:
<ping>
0
 
kousisAuthor Commented:
Lunchy
what is that mean?
0
 
LunchyCommented:
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
 
Michel SakrCommented:
try

document.location.replace("url")
0
 
hongjunCommented:
any progresses?

hongjun
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 11
  • 6
  • 3
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now