Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statechange on pushState, make it differ from back/forward button #209

Closed
pocesar opened this issue Sep 7, 2012 · 6 comments
Closed

statechange on pushState, make it differ from back/forward button #209

pocesar opened this issue Sep 7, 2012 · 6 comments

Comments

@pocesar
Copy link

pocesar commented Sep 7, 2012

Currently, im only using pushState to keep the history, since I'm loading my website content through AJAX. When I call History.pushState, statechange gets called, and call the same content twice. I'm using link event delegation on my website, and I'm having to use a 'hack' and use popstate instead of statechange.
In my code, only when the content changes I use History.pushState(), because I can't do the otherway around. Also, when going back two times using the back button, the getState returns the equivalent to -1 only, and sticks with that forever, which makes it kinda useless.

$(window).bind('popstate', function(e){
  if (typeof e['originalEvent'] !== 'undefined') {
    phery.view('#container').remote(History.getState(false, false).cleanUrl);
  }
});
@jeffwillden
Copy link

I think I have the same issue. It sounds like there's no way to pushState() without triggering a statechange, so if you only want statechange to be called for back/forward navigation, you'll have to hack around it by not calling the callback the first time it's pushed onto the stack. Does anyone else know if history.js addresses this use case more elegantly?

@tobyski
Copy link

tobyski commented Oct 25, 2012

I've run into the same problem when shifting to History.js for IE support, why History.pushState doesn't trigger a identifiably different statechange to browser buttons is odd. Indeed the work around I have in place is the same as jeff which is a pretty nasty, be nice to see a way of handling this in the event handler.

@celevra
Copy link

celevra commented Oct 26, 2012

the same problem here...

[edit]
these commits helped me out:
#137
STRML@65130dc

@pocesar
Copy link
Author

pocesar commented Oct 26, 2012

that was_expected kinda fix it, but still, the back button works just one time, and then sticks to that state forever

@celevra
Copy link

celevra commented Oct 26, 2012

no for me it is working perfectly

@pocesar
Copy link
Author

pocesar commented Oct 26, 2012

currently I decided to drop History.js and, using modernizr, check the browser support for history api natively, IE suckers can have a full page load

@pocesar pocesar closed this as completed Sep 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants