1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Rep Power

    JQuery: back button vs. clicking on link


    I have a page where the user must not be allowed to click
    on the back button. They should be forced to return to the page. However, they should be free to navigate to other pages by clicking links.
    I've implemented this logic in JQuery:

    <script type="text/javascript">
    	$(document).ready(function() {
    		$(window).bind("unload", function() {
    			alert("Cannot go back!");
    			window.location.href = "/my/page";
    However, this fires in both cases (clicking the back button and clicking any links, and also when closing the browser). I need it to fire only for the back button. How do I do that?

  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Rep Power
    Your probably going to to irritate the end-users of the website, by doing this; because they expect to be able to go to the previous page..., when they click the "Back" button. That being said; here's a forum post, that you may want to take a look at: http://stackoverflow.com/questions/1...ing-history-js.

    Comments on this post

    • imchi agrees : Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo