Search code examples
jquery-mobilepopstate

jQuery mobile loading entire page on window popstate


I have this code below

window.addEventListener('popstate', function(){
    newHref = window.location.href;
    if(pushedState){
        urlSplit = newHref.split('/');
        pageURL = urlSplit[urlSplit.length - 1];
        $('div').html('loading...');
        $.ajax({
            type : 'POST',
            url : pageURL,
            success : function(data){
                $('div').html(data);
            }
        })
    }
})

This code works fine but if I add the jQuery mobile library to my html file it causes the popstate event to run a ajax loading an entire page into my div.

I have tried doing this

$.mobile.ajaxEnable = false;

But it doesn't work. My jQuery mobile version is 1.4.5


Solution

  • From what you are showing us I presume you are not using full jQuery Mobile functionality as what you are describing is how jQuery Mobile is supposed to work.

    I also presume you do not need all jQuery Mobile functions.

    Why not rebuild jQuery Mobile library by cherry picking only functionalities you actually need: http://jquerymobile.com/download-builder/

    For example, if you do not select init this will disable global initialization of the jQuery Mobile library. You will, of course, be able to manually trigger page markup enhancement.