I m trying to trigger a specific task, like change the CSS of the element when every time user clicks on the browser's Back button.
Luckily SO got my back with the code below, which triggers when a user clicks on the back button and dees the task.
But however, this trigger on the back button click only works once per page load. Hence, the function().
Can anyone help me with how to make it get triggered whenever the back button is pressed?
Code goes as :
$(function() {
if (window.history && window.history.pushState) {
window.history.pushState('', null, './');
$(window).on('popstate', function() {
// My stuff
});
}
});
Any help is greatly appreciated.
Use event listener , i dont know how to do it in jQuery, the code will look like this
if (window.history && window.history.pushState) {
window.history.pushState('', null, './');
window.addEventListener('popstate', function() {
// My stuff
});
}
});