I am using jQuery Mobile and have few pages in one HTML page. When opening these pages, I'd like to pass parameters for them, so that their parameters are persistent in URL.
E.g.
<a href="#map?x=4&y=2"
It would open and I could access parameters X and Y in beforeshow event.
Is this possible and how? What alternative means you suggest for encoding parameters with hashbangs?
Yes, you can have links like the one you showed:
Then, on before show you can read this params with this code:
The definition of the
QueryStringToHash
(got from here) is the following:Hope this helps. Cheers
I would suggest you don't use hash 'parameters', since current support for it is buggy.
I would intercept the clicks on all links and look for a specific data- element, say, data-params:
And in your HTML you can go
In this case you are creating a global variable, called params, which you should be able to access in a uniform manner from all your code.
You will have to parse those parameters yourself though, however that's not hard, could use something like this:
Have you checked out the jQuery mobile FAQ? -> http://jquerymobile.com/test/docs/faq/pass-query-params-to-page.php
I'm currently using: https://github.com/azicchetti/jquerymobile-router