Welcome to WebmasterWorld Guest from 50.16.112.199

Forum Moderators: open

pushstate issue

pushstate issue back button

   
3:50 pm on Sep 3, 2013 (gmt 0)

5+ Year Member



I have a page that loads different lists dynamically, but also made seo friendly static pages for the lists. The buttons have 'a href' links that do a pushstate after which does replacestate. I want the history to remember only the last page clicked and go back to that static page, then when the visitor presses back once more to go to the first page (this.php).

My problem is that the first time I press back, it goes to the correct static page, but the second time i press back, it only changes the url, but doesn't change the actual page, the onpopstate doesn't trigger eighter. The curious part is that the forward button works fine through these pages, the issue only appears with the history back button.

Relevant code from 'this.php':

$(document).ready(function(){
$(".buttons").click(function() {
var element = $(this);
title = element.text();
url = element.attr("href");
if (location.pathname != '/this.php') {
history.replaceState({ path: url }, title, url);
document.title = title;
} else {
history.pushState({ path: url }, title, url);
document.title = title;
}
return false;
});
});
window.onpopstate = function(event) {
if(event && event.state) {
location.reload();
}
}


Thanks in advance
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month