1

I'd like to change my jQM page's URL dynamically (when the user does some action) in order to modify the query string. Using history.pushState works fine, but when jQM tries to add a hash to the URL, for example when navigating to a dialog, things don't work as expected: the URL reverts to its original value, and jQM appends the hash to that (not to mention that an error occurs when I try to dismiss the dialog).

I looked into the jQuery Mobile docs and, from what I understood, the original URL of a page is stored in the data-url attribute of the data-role="page" element. So I tried modifying that as well whenever I need to change my URL, but it still reverts back to the original one when a dialog is opened.

Check this JS Bin for an example: http://jsbin.com/egunif/5/edit

When clicking the "Dialog" button, the URL is changed (along with the data-url attribute) and then the dialog is opened. You can see that the url briefly changes to egunif/hashtest before jQM changes it to egunif/5#&ui-state=dialog.

So it seems that the original URL is being stored somewhere else, the question is where? And is it possible to change this URL so that there are no conflicts when jQM makes hash changes to it?

Thanks!

1 Answer 1

1

What I wound up doing was just setting the url back to its original value whenever I change page to a dialog (in a pagebeforechange handler), then re-replacing it with the new value when coming back to the page (in a pagechange handler).

I still get an error in the browser's debug console due to an empty hash value (possibly something to do with this issue), but it's not affecting the functionality of the site, so I'll leave it for now. I'm still open to better suggestions though!

Update:

In the 1.2.0 Final version of jQM, popups were introduced, along with the option to disable hash changing by setting data-history="false" on the popups. By replacing all my dialogs with popups, I am able to manipulate the url without having to worry about conflicting with jQM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.