javascript - pushState fallback for Internet Explorer? - Stack Overflow

admin2025-04-18  1

I know that IE does not support pushState, but I want a way for my users with a modern browser to enjoy the benefits while the users using older browsers don't make use of it.

Currently, the javascript code prevents my tabbed navigation from working pletely in IE, which means that cannot see a lot of the content.

Anyone know a solution for my problem?

Here's my JavaScript code:

var tabContents = $(".tab_content").hide(),
                  tabs = $(".tab_nav li");

tabs.first().addClass("active").show();
tabContents.first().show();

tabs.click(function() {
    var $this = $(this), 
        activeTab = $this.find('a').attr('href');
        history.pushState(null, '', activeTab);

    if(!$this.hasClass('active')){
        $this.addClass('active').siblings().removeClass('active');
        tabContents.hide().filter(activeTab).fadeIn();
    }

    return false;
});

$(window).bind('popstate', function(){
    $.getScript(location.href);
});

I know that IE does not support pushState, but I want a way for my users with a modern browser to enjoy the benefits while the users using older browsers don't make use of it.

Currently, the javascript code prevents my tabbed navigation from working pletely in IE, which means that cannot see a lot of the content.

Anyone know a solution for my problem?

Here's my JavaScript code:

var tabContents = $(".tab_content").hide(),
                  tabs = $(".tab_nav li");

tabs.first().addClass("active").show();
tabContents.first().show();

tabs.click(function() {
    var $this = $(this), 
        activeTab = $this.find('a').attr('href');
        history.pushState(null, '', activeTab);

    if(!$this.hasClass('active')){
        $this.addClass('active').siblings().removeClass('active');
        tabContents.hide().filter(activeTab).fadeIn();
    }

    return false;
});

$(window).bind('popstate', function(){
    $.getScript(location.href);
});
Share edited Jul 26, 2011 at 0:03 tvanfosson 533k102 gold badges700 silver badges799 bronze badges asked Jul 25, 2011 at 23:55 imjpimjp 6,70511 gold badges49 silver badges58 bronze badges 4
  • 2 By indenting your code block 4 spaces, you can format all of it without using backticks. – tvanfosson Commented Jul 26, 2011 at 0:03
  • oh sweet.. didn't know :) thanks. – imjp Commented Jul 26, 2011 at 0:05
  • The {} button on theeditor bar rocks, BTW. – hugomg Commented Jul 26, 2011 at 3:47
  • is this a duplicate of stackoverflow./questions/5527617/… – Kevin Hakanson Commented Aug 7, 2011 at 1:40
Add a ment  | 

1 Answer 1

Reset to default 4

Try the jQuery BBQ: Back Button & Query Library. I've had great success using it.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744950191a276286.html

最新回复(0)