简体   繁体   English

jQuery Mobile:在调用changePage之后,第一页又出现了

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

Basically creating a mobile app using phonegap/cordova and jquery mobile, I need to land user on a particular page from status bar notification but it shows default page for a while and go to the other page (I want to show) and ends up with default page loaded again.Here is my code: 基本上是使用phonegap / cordova和jquery mobile创建一个移动应用程序,我需要通过状态栏通知将用户放在特定页面上,但是它会显示默认页面一段时间,然后转到另一个页面(我想显示)并最终显示为默认页面再次加载。这是我的代码:

HTML 的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>

Javascript 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;
    }
}

So it shows welcome page and go to the chat page and again get back to welcome. 因此它将显示欢迎页面并转到聊天页面,然后再次返回欢迎页面。 Tried to set timeout but didn't help. 试图设置超时时间,但没有帮助。

Any solution? 有什么办法吗?

Please see if it help for you, i have used this code in phonegap android it is working fine.also check the $.mobile.changePage is deprecated from jquery mobile 1.4 请查看它是否对您有帮助,我已在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