Search code examples
javascriptjqueryjquery-mobilemobile-website

Force jQuery Mobile to update hash instead of URL for AJAX pages?


I am using the default behavior of jQuery Mobile where my href links are pointing to different pages on my site. This changes the URL completely. Is there a way to make it update the hash instead of changing the URL? The page alone does not work when going directly, so a hash would make sense (good for bookmarking). Also I would not have to worry about relative pathing from there since I remain in the root of my site. Any way to do this like it does for dialog?


Solution

  • You can disable this by setting pushStateEnabled to false.

    This is done in mobileinit event. For example:

    <script type="text/javascript">
    $(document).bind("mobileinit", function(){
        $.mobile.pushStateEnabled = false;
    });
    </script>
    
    <script src="jquery-mobile.js"></script>
    

    Note that mobileinit must be attached before jQuery mobile is included into page. For more information take a look at jQuery Mobile configuration defaults documentation page.