Search code examples
jquerymobilehashbang

jQuery Mobile Data in URL


Using jQuery Mobile, how could I create hashbang URLs such as #!/value_1/value_2 and be able to read both of these values, assuming that both parameters will always be in the same order.

One caveat is that this is being powered by a one page structure, so I'm not linking to an external page.


Solution

  • jQuery Mobile automatically maps hashbangs to page element ids (faux pages) by default. First you need to disable this behavior.

    Then you need have a custom logic which reads windows.location.hash and takes action on it either when

    • the site is loaded

    • individual faux page is openend (onpageshow JQM event)

    Creating links happens like you would create links normally - just set a href value.

    Here is more info:

    jQuery Mobile and "query parameters" for hashbang navigation