Is there a way using Jquery to detect the back button being pressed cross browsers

后端 未结 2 670
后悔当初
后悔当初 2020-11-30 09:37

I have a website that is on a slide show and when the user presses the back button I would like it to go back to the album view not the prior and prevent page. Is there a wa

相关标签:
2条回答
  • 2020-11-30 09:42

    jQuery Address provides strong cross-browser support for browser history and Ajax crawling:

    http://www.asual.com/jquery/address

    http://github.com/asual/jquery-address

    Greetings

    UPDATE:

    you can find a good sample right here:

    http://jsfiddle.net/5L6Ur/10/

    some code in short:

     $(function() {
        $('a').click(function(e) {
            e.preventDefault();
            $.address.value($(this).attr('href'));
        });
        var changecount = 0;
        $.address.change(function(e) {
            if (typeof e !== 'function') {
                $('span').html(changecount++);
            }
        });
     });​
    
    0 讨论(0)
  • 2020-11-30 10:06

    You should:

    1. Set location.hash when page state changes.
    2. When location.hash changed by user (for example, by pressing back button) render appropriate page contents.
    0 讨论(0)
提交回复
热议问题