How to find the active page of the first page in jQM?

I need to get the id of the element of the active page loaded . I know what we can use $.mobile.activePageto get the current page in sight, and that we can get the identifier of this element with $.mobile.activePage.attr('id'). However, this is the first time you download the application undefined. In my specific application, I want users to be able to type from any URL, and I need to know the loaded page in order to properly initialize my navigation system.

$(document).bind('pageinit', function() { 
    if($.mobile.activePage !== undefined) {
        console.log($.mobile.activePage.attr('id'));
    }
    else {
        console.log('1st page load detected');
    }
});

Outputs: 1st page load detected upon first loading and identifier on each subsequent page. How can I get the identifier on first boot?!?

+3
source share
1 answer

, , pageinit .

, ( changePage). 3639 JQM .

.

, :

pagebeforeload = triggered before the load request (inside changepage) is made
pageload = triggered after the page was loaded
pagebeforechange = triggered before a changepage is made
pagechange = triggered after changepage is done
pagebeforeshow = triggered before the page is shown
pageshow = triggered when the page is shown

pagebeforeshow, , .

, !

+11

All Articles