Skip to content


Subversion checkout URL

You can clone with
Download ZIP


_preventDefault doesn't work with HTML5 history api #162

rhec opened this Issue · 1 comment

2 participants


It works with the hash change method, but when using the HTML5 history api it will generate an error because window.history.popState is not a method that exists.
You can see it is not listed in the mozilla documentation and I've confirmed in the console that it does not exist in Chrome. I'm not sure what browser, if any, implements it.
I haven't been able to figure out a workaround, since the state has already changed by the time my event handlers are called, and there is no way to remove items from the history once you've pushed them on there. Perhaps, instead of using preventDefault to cancel the event after it has occurred, it would make sense to add a beforeChange function that can stop the change from occurring at all by returning false? Similar to how the form onsubmit event is handled.


Thanks for reporting that!

This feature was contributed some months ago and I haven't looked much into it until now. I revised it yesterday and basically dropped most of the code. Please, pull the latest version and check if it works for you.

Event cancellation should work fine for internal events but I'm not sure I'll be able to enable it for external events like the browser back button. I did some tests but I wasn't able to prevent the default popstate event and I still haven't checked how the hashchange event behaves in the same situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.