开发者

HTML5 history in iOS safari 4.2.1 broken, Old webkit bug?

开发者 https://www.devze.com 2023-02-18 07:39 出处:网络
Merged with window.history.pushState not going back in history. In regular safari my script changes the url of the page window.history.pushState and that works just fine but in ios, someh
Merged with window.history.pushState not going back in history.

In regular safari my script changes the url of the page window.history.pushState and that works just fine but in ios, somehow the URL that gets loaded it that of the last page... It is really frustrating! is this a bug?

Thanks for your help :)

here is the code:

    function hijackLinks() {

        $('a').live("click", function (e) {
            e.preventDefault();
            loadPage(e.target.href);            
            $(this).addClass('click');

        });
        if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {$('a').live("touchstart", function (e) {
             direction = $(this).attr('class');
            $(this).addClass('temp');
             setTimeout(function () {
                    $('.temp').addClass('click');
                }, 100);
        });
        $('a').live("touchmove", function (e) {
            $('.temp').removeClass('temp');
            setTimeout(function () {
                    $('.click').removeClass('click');
                }, 1);})

            $('.click').live("touchend", function (e) {开发者_如何学C


             setTimeout(function () {
                    $('.click').removeClass('click');
                }, 1);})}
                else{
         $('a').live("mouseenter", function (e) {
            direction = $(this).attr('class');
             $(this).addClass('click');})
              $('a').live("mouseleave", function (e) {

             $(this).removeClass('click');})

                }

    }


    function loadPage(url) {

        if (url === undefined) {

            $('body').load('url', 'header:first,#content,footer', hijackLinks);
        } else {
            $.get(url, function (data) {
                $('body').append(data);
                sm = $(window).width();
                sn = $(window).scrollTop();

             window.scrollTo(0,0);

             window.history.pushState(null, null, url);

                if (direction === "leftnav") {
                    $('body>header:last,body>#content:last,footer:last').css("-webkit-transform", "translate( -" + sm + "px,0px)");
                    footerheight = $('body>#content:last').outerHeight(false) + $('body>header:last').outerHeight(true);
                    $('footer:last').css("top", footerheight);
                    $('body>header,body>#content,footer').css("-webkit-transition-duration", "0.5s");
                    $('body>header:first,body>#content:first,footer:first').css("-webkit-transform", "translate(" + sm + "px,0px)");
                    $('body>header:last,body>#content:last,footer:last').css({"-webkit-transform": "translate(0,0)"});


                }
                if (direction !== "leftnav") {
                    $('body>header:last,body>#content:last,footer:last').css("-webkit-transform", "translate(" + sm + "px,0px)");

                    footerheight = $('body>#content:last').outerHeight(false) + $('body>header:last').outerHeight(true);
                    $('footer:last').css("top", footerheight);
                    $('body>header,body>#content,footer').css("-webkit-transition-duration", "0.5s");


                    $('body>header:first,body>#content:first,footer:first').css("-webkit-transform", "translate( -" + sm + "px,0px)");
                    $('body>header:last,body>#content:last,footer:last').css("-webkit-transform", "translate(0,0)");

                }

                setTimeout(function () {
                    $('body>header:not(:last),body>footer:not(:last),body>#content:not(:last)').remove();

                    $('body>header,body>footer,body>#content').removeAttr('style');
                },1000);




            });


        }
    }



    $(document).ready(function () {
        loadPage();

    });
    window.addEventListener("popstate", function(e) {
    loadPage(location.pathname);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消