iOS safari 4.2.1中的HTML5历史记录,旧的webkit bug?

时间:2011-03-22 23:19:09

标签: jquery ios html5 mobile-safari browser-history

在常规的safari中,我的脚本更改了页面window.history.pushState的url,并且工作得很好但是在ios中,不知何故,将URL加载到最后一页的URL ...真的很令人沮丧!这是一个错误吗?

感谢您的帮助:)

这是代码:

    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) {


             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 个答案:

没有答案