jQuery Mobile get current page

后端 未结 8 1319
孤城傲影
孤城傲影 2021-02-04 01:44

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

相关标签:
8条回答
  • 2021-02-04 02:27

    We're doing this:

    $(document).on("pagecontainershow", function() {
        var activePage = $.mobile.pageContainer.pagecontainer("getActivePage");
    
        var activePageId = activePage[0].id;
    
        if(activePageId != 'splashPage') { //fix rotation splash flash bug
            $("#splashPage").hide();
        } else {
            $("#splashPage").show();
        }
    
        switch(activePageId) {
            case 'loginPage':
                loginPageShow();
                break;
            case 'notificationPage':
                notificationPageShow();
                break;
            case 'postPage':
                postPageShow();
                break;
            case 'profilePage':
                profilePageShow();
                break;
            case 'splashPage':
                splashPageShow();
                break;
            case 'timelinePage':
                timelinePageShow();
                break;
            default:
                break;
        }
    });
    

    And navigation works like this:

        $.mobile.loading('hide');
        $(":mobile-pagecontainer").pagecontainer("change", "#timelinePage", {
            transition: 'none'
        });
    
    0 讨论(0)
  • 2021-02-04 02:28

    Both of this solutions are good but I needed to put it inside document.ready(function()

    $(document).ready(function(){
    var activePage = $.mobile.activePage[0].id;
    alert(activePage);
    });
    
    0 讨论(0)
  • 2021-02-04 02:29

    Jquery mobile 1.4.3 friendly...

    $(document).on('pagebeforeshow', function () {
        var URL = $.mobile.path.parseUrl(window.location).toString().toLowerCase();
    
        alert(URL);
    });
    
    0 讨论(0)
  • 2021-02-04 02:30

    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/

    0 讨论(0)
  • 2021-02-04 02:35
    $(document).ready(function() {
    
    //exit when back button pressed on home screen
    document.addEventListener("deviceready", function() {
        document.addEventListener("backbutton", function() {
            if ($.mobile.activePage.attr('id') == "home") {
                navigator.app.exitApp();
            } else {
                navigator.app.backHistory();
            }
        }, false);
    }, false);
    

    });

    0 讨论(0)
  • 2021-02-04 02:42
    $(document).live('pagebeforeshow', function() {
        alert($.mobile.activePage.attr('id'));
    });​
    

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

    0 讨论(0)
提交回复
热议问题