Showing posts with label go_back. Show all posts
Showing posts with label go_back. Show all posts

Tuesday, November 27, 2012

jQuery Back Button (go to previous page)

You can check history length by jQuery and if can not possible to go back you can remove it.

First in html page introduce a hyperlink:
<a href="javascript:void(0)" class="back_link">Back</a>

Then add the jQuery code block:
<script type='text/javascript'>
    if(history.length <= 1) {
        jQuery(".back_link").remove();
    }
    jQuery(".back_link").bind("click", function() {
        if(history.length > 1) {
            parent.history.back();
        }
        return false;
    });
</script>