0

I have a long page which navigates via scrollTop().

Because scrollTop() doesn't work propperly with back buttons of browsers (the browsers ignore it) I want to try and refresh the browser on every popstate, then it would work and the users scroll position would be where its supposed to be.

Problem is my code results in infinite refresh.

    $(window).bind('popstate', function(event) {
        //var path = window.location.pathname;
        //var filename = path.match(/.*\/([^/]+)\.([^?]+)/i)[1];
        //var pos = "#" + filename;
        //$(document).scrollTop(pos);
        location.reload();
    });

How can I fix it to refresh only once? I tried one() but its the same.

user1721135
  • 6,122
  • 8
  • 29
  • 58

1 Answers1

-1

There are lots of jQuery and plain JS plugins for browser history, that will do what you want.
I don't think refreshing page will enable browser history for you.

jQuery BBQ:
http://benalman.com/projects/jquery-bbq-plugin/
demo:
http://benalman.com/code/projects/jquery-bbq/examples/fragment-basic/#chicken.html

History JS
https://github.com/browserstate/history.js/

Sergej Popov
  • 2,745
  • 5
  • 31
  • 52
  • I am using history api, the problem is in scrolling, not in general history implementation. Browsers take control of the scrolling position when navigating back/forward. The ajax stuff, which i also have works just fine. – user1721135 May 12 '13 at 10:05
  • It would work if I could get the browser to refresh only once on popstate. All the plugins dont work for this, because of the scrolling, if it was just ajax, then yes, they would work. – user1721135 May 12 '13 at 10:25