Skip to content Skip to sidebar Skip to footer

Jquery Mobile Get Current Page

I am using jQuery Mobile 1.1.1 and Apache Cordova 2.0.0. I want my app to exit when I press back button but only if current page have ID = feedZive. I am using following code to do

Solution 1:

$(document).live('pagebeforeshow', function() {
    alert($.mobile.activePage.attr('id'));
});​

http://jsfiddle.net/ajD6w/5/

Solution 2:

Try using

var activePage = $.mobile.activePage.attr("id");

I made a working jsfiddle for you http://jsfiddle.net/Z5Uze/1/

Solution 3:

I realise this is an old thread, so this is probably a more recent addition.

Have you tried:

var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
if(activepage[0].id == yourpageid)
{ /*do something here*/ }

or another way:

var activePage = $.mobile.activePage.attr('id')
if(activepage == yourpageid)
{ /*do something here*/ }

Solution 4:

Try this, it's working for me:

var activePage = $.mobile.activePage[0].id;

Here is a Fiddle with an alert that is working: http://jsfiddle.net/9XThY/3/

Solution 5:

$(document).ready(function() {

//exit when back button pressed on home screendocument.addEventListener("deviceready", function() {
    document.addEventListener("backbutton", function() {
        if ($.mobile.activePage.attr('id') == "home") {
            navigator.app.exitApp();
        } else {
            navigator.app.backHistory();
        }
    }, false);
}, false);

});

Post a Comment for "Jquery Mobile Get Current Page"