How to disable Browser back button?

Hi friends,
Is there a way to disable the Back button in the Browser. Give details.
falkonAsked:
Who is Participating?
 
farajConnect With a Mentor Commented:
The location object's replace() method overwrites the current history entry with the specified URL. It removes the current history entry before the next URL is loaded. Removing the item from the history list also prevents users from seeing the page again by clicking on the Back button later.
This technique is very useful for online games and multi-page forms, where you want prevent the user from returning to the previous page. Furthermore, the location.replace() method is supported by all browsers except Navigator 2.0x. The following example shows how to use this method in a link:


<A HREF="javascript:location.replace('nextpage.html')">Advance</A>
0
 
a.marshCommented:
Basically you can't - at least not 100% guaranteed.

Check out:

http://developer.irt.org/script/311.htm

:o)

Ant
0
 
LorangerGCommented:
a. marsh is correct but you can try the following:

1) You can use the location replace method when changing the location. This replaces the current history location with the new location. However older browsers do not support this method, which is why it is required to test for the images object:

<script language="JavaScript"><!--
if (document.images)
    location.replace('http://www.somewhere.com/apage.html');
else
    location.href = 'apage.html';
//--></script>

 

Note: in Opera replace() will work, but only with absolute URL's.

2) You can load the new location into another window, and then close the old window:

In the first page:

<script langauge="JavaScript"><!--
function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); }
//--></script>

<a href="javascript:newWindow('1.html','window1')">Open Window</a>

 

In the next window:

<script language="JavaScript"><!--
function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); }
function replaceURL(fileName) { newWindow(fileName,'window2'); self.close(); }
//--></script>

<a href="javascript:replaceURL('2.html')">change location</a>

 

3) You can open a window without a toolbar:

<script language="JavaScript"><!--
msgWindow=window.open('apage.html','windowName','toolbar=no');
//--></script>

 

However, this does not totally stop the user from being able to go back to the previous page.

4) You can add code to the previous page to force the browser to go forwards again:

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

 
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
LorangerGCommented:

 Wait a minute. Sorry a. marsh, I did not see you URL. Falcon, the methods I commented on are in the URL a. marsh recommended. Sorry marsh, I wasn't trying to scope your points.
0
 
a.marshCommented:
Apology accepted. :o)

falkon, please note that if you find the comments that LorangerG gave useful, then you should accept MY comment as the answer as the URL says almost EXACTLY the same thing!

Did you copy and paste the text LorangerG?

:o)

Ant
0
 
WebDevOneCommented:

 It DOES say the exact same thing. Yes, it's pasted from the source.
0
 
hongjunCommented:
faraj,

You are here long enough to know EE policy. The policy here is to post everyhing in comments. Questionner will then have the option to accept a comment as an answer. Posting as a proposed answer will lock the question and thus restrict the exposure to more experts. We know you are new here and thus is forgiven. With the current version of EE, you do not have the option to convert your answer to a comment but this can be done by the questioner himself. I advise the questionner to reject his answer so that this question will be released to more experts. You can however accept his comment again if you find it is really helpful.


Anyway, faraj's comment is being covered by links posted by many of the above comments including mine.

Thanks
hongjun
0
 
a.marshCommented:
falkon, please reject the proposed answer.

Ant
0
 
hongjunCommented:
Why there's no justice in EE? I personally feels that faraj's answer is a repeated one. Bad choice falkon.

hongjun
0
 
modderCommented:
>Why there's no justice in EE?

There is now.
0
 
modderCommented:
OK. Here is what I've done:

1) Increased points from 100 to 200. falkon can have the extra 100 points back if (s)he has the decency to return to this question and explain what is going on.

2) Reduced faraj's expert points to ensure that faraj has not benefited from this question.

3) Posted a new question, http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=javascript&qid=20156939, for a.marsh, to give you the points you deserved.

modder
Community Support
0
 
a.marshCommented:
Great job modder. Thank you.

:o)

Ant
0
 
hongjunCommented:
Great.

hongjun
0
 
falkonAuthor Commented:
Hai guys,
I am sorry. In a hurry i did that and i didnt have much time to go thro' all those comments when accepted faraj's answer.
0
 
modderCommented:
Hai falkon,

I am sorry. In a hurry. I don't have much time to deal with users who cannot be bothered to participate in Experts-Exchange in a constructive manner so I have closed your account.

Everybody else, sorry it took me a while to finalize this.
0
 
EvolutionmarketplaceCommented:
Try this:

<script>
history.forward();
</script>

Pablo.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.