1

I am using $.mobile in my app. I must create my own routing system. I bind observer on hashchange and I pull out interesting data from location.hash. I have a problem - jQuery.mobile removes the hash sign from location.hash if it has a slashes ( e.g. from 'lalal/#controller/action/param' to 'lalal/controller/action/param' and $.mobile says in yellow box Error Loading Page.

I tried to unbind existing "hashchange" in first, but then pages not load automatically ( what I require ).

How to prevent changes of hash, but that jQuery must still load the page automatically( e.g. by its ID declared in element having data-role='page')? . Below is a fragment of my router class: ( Router.load doesn't change location.hash )

__construct: function() {   

        var that = this; 
        $( window ).bind( "hashchange" , function( e ) {
            //e.stopImmediatePropagation()
            that.load( this.location.hash  ); 

        });  
    }
Jasper
  • 75,717
  • 14
  • 151
  • 146
abuduba
  • 4,986
  • 7
  • 26
  • 43
  • 1
    What version of jQM and jQuery are you running? as in RC1 and RC2 there where some bug fixes to hashchange – Phill Pafford Nov 16 '11 at 22:15
  • Do you mean the latest jQuery 1.7 and jQueryMobile RC3? Just to note jQuery 1.7 is not supported yet by jQM, so 1.6.4 is the version you should be running – Phill Pafford Nov 17 '11 at 14:09

2 Answers2

6

I believe you are fighting against the "pushState" plugin in jQuery Mobile added in Beta 3 (I believe). You can disable this plugin with the following code (used before you include the jQuery Mobile JavaScript file):

$(document).on('mobileinit', function () {
    $.mobile.pushStateEnabled = false;
});

Check-out the documentation here (notice the "pushState Plugin" section): http://jquerymobile.com/demos/1.0rc3/docs/pages/page-navmodel.html

Jasper
  • 75,717
  • 14
  • 151
  • 146
  • 1
    Disabling pushStateEnabled makes that hash sign no longer disappear from adress bar - ok, but `$.mobile` still tries to load pages using ajax( only when hash contain slashes) - even when `$.mobile.ajaxEnabled = false`;of course with status 404 and jqm is firing page load error – abuduba Nov 17 '11 at 07:39
0

in your html after including jquery and before including jquery.mobile-1.x.y.js add:

<script>
$(document).bind("mobileinit", function(){
        $.mobile.pushStateEnabled = false;
        $.mobile.ajaxEnabled = false;
        $.mobile.hashListeningEnabled = false;
});
</script>
pQd
  • 116
  • 4
  • 20