browser back button delete a class

1

I'm making a website that works on a single page. So when I click on a menu button it scrolls to the area I want with:

$('html, body').animate({scrollTop: $('#nomedoid').offset().top},Math.abs(0));

And at the same time I put the window.history.pushState:

window.history.pushState(null, 'blablabla', 'link');

It works as I expected, if I click the back button of the browser (or cell phone) the site goes back to the last page of the site, including scrolling to it.

The problem: There is now a "page" that opens on the site, enter a div in front of the site with addClass and also give the window.history.pushState:

$('.frente_site').addClass('frente_site_aparece');
window.history.pushState(null, 'blablabla', 'link-frente');

There you go back in the browser until the URL changes, but it does not removeClass in the class '.frente_site'. How could this happen? Am I doing the wrong thing?

    
asked by anonymous 29.03.2017 / 19:34

1 answer

1

I ended up finding a way, if not ideal, let me know!

I used this function:

window.onpopstate = function (event) {
    if(qualLink == 'perfil'){
        // faz algo
    }
}

I only feed the variable calledLink every time I change the URL and then check it with onpopstate.

    
29.03.2017 / 20:23