Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Disable Back button.

 
Logged in as: Guest
arrSession:exec spGetSession 2,7,446
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Disable Back button.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Disable Back button. - 10/22/2001 12:14:25 PM   
  Hector Sanchez

 

Posts: 3
Score: 0
Joined: 10/22/2001
From:
Status: offline
Original message moved by Snipah
Reason : JavaScript discussion...
Is it possible to disable the Back button on the Internet Explorer using code on the page? If is possible, please let me know the how.

Thanks.
 
 
Post #: 1
 
 Re: Disable Back button. - 10/25/2001 10:51:54 AM   
  pagooda

 

Posts: 54
Score: 0
Joined: 5/23/2001
From: USA
Status: offline
I have been a web programmer for years and never been able to disable back button completely, you can however make it harder for your visitors to go back to previous page.

I found this interesting article at irt.org, hope this can help


Search AboutīThe Webfor Go

Recommended Site Free Newsletters | How To's | About Computing | Aboutī


Reliagility, Inc.
Website Monitoring Services and Software. Know about downtime before your customers do!

Sponsored Link | Donate to the American Red Cross


Q311 How do I disable the "Back" button of a browser?
Home Articles FAQs Xref Games BBS Resources Dictionary Software News Books Downloads About Beta Find Site Map

irt.org | Knowledge Base | JavaScript | History | Q311 [ previous next ]

Easy answer - you can't.

Longer answer - you cannot totally remove the ability for the user to go back to the previous location, although you can make it harder.

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>



irt.org | Knowledge Base | JavaScript | History | Q311 [ previous next ]

Q311 How do I disable the "Back" button of a browser?

Amazon Recommends:

Pure JavaScript
R. Allen Wyke
JavaScript
John Pollock
JavaScript Bible, Gold Edition
Danny Goodman
HTML & JavaScript for Visual Learners
Chris Charuhas
XML How to Program
Harvey M. Deitel

Privacy Information

Home Articles FAQs Xref Games BBS Resources Dictionary Software News Books Downloads About Beta Find Site Map
irt.org Newsletter

Search irt.org



Ask A Question / Send an Answer

Provide Feedback on the "Q311 How do I disable the "Back" button of a browser?"

21:53:33 11/09/00 Phil
14:08:05 1/28/00 Scott
Last Updated: 24th June 2001
Maintained by: Martin Webb and Michel Plungjan
Copyright é 1996-2001 irt.org, All Rights Reserved.
irt.org liability, trademark, document use and software licensing rules apply. Your interactions with this site are in accordance with our public privacy statements.

Sponsored Links
Reliagility, Inc.
Website Monitoring Services and Software. Know about downtime before your customers do!
Supercharge Your Website Chat, $99
Add Live Collaboration with OHL Forum. Guests meet, chat, import & annotate images, web browse together. Moderator tools,$250, create surveys & collect data. Join a Free Demo Now!
RackSpace Managed Hosting
Rackspace Managed Hosting offers a first-class data center, customized servers, burstable bandwidth, 24x7 Tech Support and 99.999% uptime guarantee. Custom configure your server today!

Donate to the American Red Cross

Sponsored Links About Perl
RackSpace Managed Hosting
Rackspace Managed Hosting offers a first-class data center, customized servers, burstable bandwidth, 24x7 Tech Support and 99.999% uptime guarantee. Custom configure your server today!
http://www.rackspace.com/
Canadian Web Hosting
Clic.net provides Premium web hosting services as well as professional web development, since 1994 - Call us now
http://www.clic.net/
Reliagility, Inc.
Website Monitoring Services and Software. Know about downtime before your customers do!
http://reliagility.com/
Supercharge Your Website Chat, $99
Add Live Collaboration with OHL Forum. Guests meet, chat, import & annotate images, web browse together. Moderator tools,$250, create surveys & collect data. Join a Free Demo Now!
http://www.officehourslive.com/
Anderson & Shippey - We Protect Imagination
Intellectual Property Solutions. Trademark, Copyright and Domain Name: Registration, Counsel and Enforcement. Comprehensively protecting entrepreneurs from business interference.
http://www.BrandXperts.com/
Buy a Link Now!


Reliagility, Inc.
Website Monitoring Services and Software. Know about downtime before your customers do!

Sponsored Link | Donate to the American Red Cross

(in reply to Hector Sanchez)
 
 
Post #: 2
 
 RE: Disable Back button. - 10/28/2005 1:46:45 AM   
  Snipah


Posts: 1341
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
I would opt for the Location.replace (JavaScript)

replace Method
The replace method replaces the current History entry with the specified URL. After calling the replace method, you cannot navigate back to the previous URL using the browser's Back button.

Syntax: location.replace(URL)


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to Hector Sanchez)
 
 
Post #: 3
 
 RE: Disable Back button. - 10/29/2005 3:30:58 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
The best way I've come across is, as Snipah said, to use location.replace() for all your links.

you could also do this:

<body onKeydown="if (event.keyCode == 8){return false;}">

You would have to do the same for Alt+Left Arrow as well (Alt == 18, Left == 37). These keyboard shortcuts will differ for each browser.

And for the button on top....have your site load into a popup window to remove it (If you can convince the user to even open a popup window).

Another cheap method is to make a hidden/offscreen input box on the page  and use that to capture focus (disabling the backspace key). Using the blur and focus methods you could effectively capture the cursor.

You also have to disable the contextmenu in order to avoid using the back button there:

<body oncontextmenu="return false">

or you can do this on your other pages:

<body onLoad="history.go(+1)">

when the page loads, it will redirect to the page in front of it, and if there isn't a page in front of it, then nothing will happen.

In case the user wants to get smart and turn off javascript and visit your page, put this in your webpage:

<noscript>
<META NAME="Refresh" CONTENT="1; URL=MyOtherPage.html">
</noscript>

Nothing is perfect of course but these should at least get the point across to the avg user

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to Snipah)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Disable Back button. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts