homepage Welcome to WebmasterWorld Guest from 54.204.127.191
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
pushstate issue
pushstate issue back button
jaruba




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

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

 

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved