Jquery Mobile:在调用changePage后返回第一页

时间:2015-03-27 03:02:27

标签: javascript jquery cordova jquery-mobile

基本上使用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>

的Javascript

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

因此它显示欢迎页面并转到聊天页面并再次欢迎回来。试图设置超时但没有帮助。

任何解决方案?

1 个答案:

答案 0 :(得分:0)

请看看它对你有用,我在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");
        }
    }