ASP Snippets

Categories






Alerts

Free Alerts

Your email will always be
private and will not be shared.




Follow us on twitter.




Zoom In | Zoom Out


Author is awarded Most Valuable Professional award by Microsoft ASP/ASP.Net

Disable Browser Back Button Functionality using JavaScript

Author:Mudassar Khan

In this article, I am discussing how to prevent user from navigate to previous page using back button of the browser or the back option in the context menu.

One cannot disable the browser back button functionality only thing that can be done is prevent them.

Below is the JavaScript snippets that needs to be placed in the head section of the page where you don’t want the user to revisit using the back button

<script type = "text/javascript" >

   function preventBack(){window.history.forward();}

    setTimeout("preventBack()", 0);

    window.onunload=function(){null};

</script>


Suppose there are two pages Page1.aspx and Page2.aspx and Page1.aspx redirects to Page2.aspx

Hence to prevent user from visiting Page1.aspx using Back Button you will need to place the above script in the head section of Page1.aspx as shown below.



Writing the code to disable back button

I have tested the script in the following browsers

1.     Internet Explorer 5.55

2.     Internet Explorer 6

3.     Internet Explorer 7

4.     Mozilla Firefox 3

5.     Opera 9

6.     Safari 4

7.     Google Chrome

 

Try the demo here


You can download the source from here


DisableBrowserBackButton.zip (2.89 kb)

Posted: Mar 24 2009, 03:37 by Mudassar Khan | Comments (44) RSS comment feed |
Filed under: JavaScript

Views: 17433
Page copy protected against web site content infringement by Copyscape


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share





Comments

Add comment


 

biuquote
  • Comment
  • Preview
Loading




0  +  0  =   










Community News





Web Hosting SpotLight


Consulting


For consulting and work related queries click here.



Advertise


Advertise with us. For more details click here.


Suggestions


Please provide your valuable suggesstions here.

This Site is hosted on

Lunarpages.com Web Hosting