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

    Join Date
    Jun 2003
    Posts
    178
    Rep Power
    28

    JQuery: back button vs. clicking on link


    Hi,

    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:

    Code:
    <script type="text/javascript">
    	$(document).ready(function() {
    		$(window).bind("unload", function() {
    			alert("Cannot go back!");
    			window.location.href = "/my/page";
    		});
    	});
    </script>
    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?

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

    Join Date
    Aug 2008
    Posts
    1,153
    Rep Power
    183
    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