Skip to content

Jquery Mobile – how to change hash without triggering page change event

December 20, 2011

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.


From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: