簡體   English   中英

jQuery Mobile:在調用changePage之后,第一頁又出現了

[英]Jquery Mobile: First page appears back after changePage called

基本上是使用phonegap / cordova和jquery mobile創建一個移動應用程序,我需要通過狀態欄通知將用戶放在特定頁面上,但是它會顯示默認頁面一段時間,然后轉到另一個頁面(我想顯示)並最終顯示為默認頁面再次加載。這是我的代碼:

的HTML

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="width=device-width, user-scalable=no">

        <link rel="stylesheet" href="css/jquery.mobile-1.4.5.min.css" />
        <link rel="stylesheet" href="css/style.css" />
        <title>App name</title>
    </head>
    <body>
    <!--***************************Start Welcome Page*********************************** -->
    <div data-role="page" data-theme='b' id="welcome" class="demo-page">
        <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
            <h1>App name</h1>           
        </div>
        <div data-role="content">
            content here
        </div>
        <div data-role="footer" data-theme='b' data-position="fixed" data-tap-toggle="false" class="footer">

        </div>
    </div>
    <!--***************************End of Welcome page********************************************-->
    <!--***************************Start Login Page*********************************** -->
    <div data-role="page" data-theme='b' id="login" class="demo-page">
        <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
            <h1>App name</h1>           
        </div>
        <div data-role="content">
            content here
        </div>
        <div data-role="footer" data-theme='b' data-position="fixed" data-tap-toggle="false" class="footer">

        </div>
    </div>
    <!--***************************End Login Page*********************************** -->
    <!--***************************Start chat Page*********************************** -->
    <div data-role="page" data-theme='b' id="chat" class="demo-page">
        <div data-role="header" data-position="fixed" data-tap-toggle="false" data-theme='b'>
            <h1>App name</h1>           
        </div>
        <div data-role="content">
            content here
        </div>
        <div data-role="footer" data-theme='b' data-position="fixed" data-tap-toggle="false" class="footer">

        </div>
    </div>
    <!--***************************end chat Page*********************************** -->
        <script type="text/javascript" src="cordova.js"></script>
    <!-- Jquery mobile -->
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="js/jquery.mobile-1.4.5.min.js"></script>

    <!-- Jquery mobile -->
    <script type="text/javascript" src="js/PushNotification.js"></script>
    <script src="js/main.js"></script> 
    </body>
</html>

Java腳本

function onNotification(e) {    
    switch( e.event )
    {
        case 'registered':

        break;

        case 'message':
            if (e.foreground)
            {   // Status bar notification if app is in foreground          
                navigator.notification.beep(1);
            }
            else
            {   // after clicking on status bar notification
                $.mobile.changePage('#chat');

            }
            // notifications when app is open           
        break;
        case 'error':
            //$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
        break; 
        default:
            //$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
        break;
    }
}

因此它將顯示歡迎頁面並轉到聊天頁面,然后再次返回歡迎頁面。 試圖設置超時時間,但沒有幫助。

有什么辦法嗎?

請查看它是否對您有幫助,我已在phonegap android中使用此代碼,它工作正常。還請檢查$ .mobile.changePage是否從jquery mobile 1.4中棄用

onNotificationGCM: function (e) {
        var open = false;
        switch (e.event) {
            case 'registered':
                break;
            case 'message':
                if (e.foreground) {
                    //App.alertMsg("New message received", "Notification");
                }
                else {
                    open = true;
                }
                break;
            case 'error':
               // App.alertMsg(e.msg, "NotificationFail");
                break;
            default:
                //App.alertMsg("Unknown", "Notification");
                break;
        }
        if (open) {
            $.mobile.pageContainer.pagecontainer('change', "#chat");
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM