开发者

hashchange, pushState with jQuery BBQ -- Adding characters to URL

开发者 https://www.devze.com 2023-03-31 02:25 出处:网络
I have a Fiddle to look at. The hashchange will not work in jsFiddle, but you can at 开发者_如何学JAVAleast see the code:

I have a Fiddle to look at. The hashchange will not work in jsFiddle, but you can at 开发者_如何学JAVAleast see the code:

http://jsfiddle.net/LpgFt/

When I click on links the URL changes to:

index.html#url=%23about-us

rather than:

index.html#about-us

Any ideas what I'm doing wrong?


you can change your code to $.bbq.pushState({ href });

Check out this fiddle (not in iframe) ... and the actual fiddle

Updated code

$('a').click(function(){
  var href = $(this).attr( "href" );
  $.bbq.pushState({ href });
  return false;
});

 $(window).bind( "hashchange", function(e) {
    var url = e.getState( "url" );
    $("a").each(function(){
      var href = $(this).attr( "href" );
    });
  });

  $(window).trigger( "hashchange" );
0

精彩评论

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

关注公众号