Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

pushstate issue

pushstate issue back button

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

New User

5+ Year Member

joined:May 12, 2009
posts: 21
votes: 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':

$(".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) {

Thanks in advance

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members