Search code examples
jqueryhashchangepushstate

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


I have a Fiddle to look at. The hashchange will not work in jsFiddle, but you can at least 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?


Solution

  • 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" );