Going back with my browser = wrong active class link

See here that the active class is always set on the homepage link -when I go back with the browser-

I am working on a wordpress website, all pages are loaded with Ajax.js.
Everything is working, changing pages without loading all of the website, changing the url after click…
but ONE problem remain : when I click on ” go back on my browser, the active class link is ALWAYS the first page name.
Where does that come from ?

Here is my a part of my code


    $(window).bind('popstate', function() {

    var url = window.location;
    var hash = url.href.substring(url.href.lastIndexOf('/') + 1);

    $('#contenu').load( url + ' #contenu');

    $('#menu li').removeClass('active');

    if(hash.length == 0) {
        $('#menu li').first().addClass('active');
    } else {
        $('#menu li.'+hash+'').addClass('active');



$('#menu a').click(function(e){

    $('#menu li').removeClass('active');

    var lien = $(this).attr('href');

    $('#contenu').slideUp(500, function() {

        $('#contenu').load( lien + ' #contenu', function(){

            $('#contenu').slideDown(500, function(){

        history.pushState(null, null, lien);


    }); }); });

And an image

Read more here: Going back with my browser = wrong active class link

Leave a Reply

Your email address will not be published. Required fields are marked *