Computer Tips From A Computer Guy

Computer Tips From A Computer Guy


How to disable Back button in Internet browser

Posted: 26 Aug 2009 03:28 AM PDT

Ever been to one of those sites where you try to click the Back button, but nothing happens? Instead of going back to the previous page you were on, it just keeps reloading the same page??

Yeah that's pretty annoying, but lots of websites do it! In this post, I'll teach you how you can also do it, though I only recommend it in specific instances. Do not put this code on your entire website, otherwise it will ruin the user experience.

If there is a page that you need to ensure people cannot click Back to get to, such as when completing a checkout process or something, then use this technique. Also, note that it may not work in all browsers or browsers in which Javascript is disabled.

Unfortunately, there is not one piece of code that always works. Basically, there is a function called forward in JavaScript that lets you automatically send someone back to the page they just came from.

So on the page that you do not want people to be able to come back to, try this code:

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

Or you can try this JavaScript code:

onLoad=”if(history.length>0)history.go(+1)”

If you're not having much luck with that, try this out:

<script language=”javascript”>
window.history.forward(1);
</script>

Or even more simply, you can try this:

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

Make sure to put that on the page before the one you want people to remain on. So if a user clicks from Page 1 to Page 2 and you want them to stay on Page 2, add the code to Page 1.

Another trick you can do is to simple replace the previous page in history with the current page. So when they go back, the history page will actually be the same page. You can do that by using:

location.replace(this)

Another way is to simply load a new window and to set the new window to not have a toolbar. So if there is a particular set of pages that you want to ensure the user cannot click Back on, just load the first page in that process in a new window with no toolbars.

So even though there is technically no way to disable the Back button in an Internet browser, you can use some JavaScript tricks to get a similar result. Enjoy!


Copyright © 2007
Online Tech Tips.
Aseem Kishore (digitalfingerprint: a59a56dce36427d83e23b501579944fcakmk1980 (74.125.44.136) )

Post from:

How to disable Back button in Internet browser