Jquery Mobile – how to change hash without triggering page change event
I needed to handle the beforepagechange event in order to customize the hash value for bookmarking purpose. But the problem is the page change event chain gets triggered when I update the hash.
windows.location.hash = newHash;
The reason is jquery listens on the hash value. hashListeningEnabled disables hash listening all together, but I just want to disable hash listening specifically in just one function.
I dug into the jquery source code and found an undocumented variable that does the trick. (It’s not documented as far as I know. I’ve been looking for a while). I’m not sure if this is good practice in jquery, but it works.
$.mobile.urlHistory.ignoreNextHashChange = true; window.location.hash = newHash;
This variable gets reverted to false in jquery built-in _handleHashChange function.