Javascript jquerymobile:changePage调用后返回第一页
基本上,我使用phonegap/cordova和jquery mobile创建了一个移动应用程序,我需要让用户在状态栏通知的某个特定页面上登陆,但它会显示一段时间的默认页面,然后转到另一个页面(我想显示),最后再次加载默认页面。下面是我的代码: HTMLJavascript jquerymobile:changePage调用后返回第一页,javascript,jquery,cordova,jquery-mobile,Javascript,Jquery,Cordova,Jquery Mobile,基本上,我使用phonegap/cordova和jquery mobile创建了一个移动应用程序,我需要让用户在状态栏通知的某个特定页面上登陆,但它会显示一段时间的默认页面,然后转到另一个页面(我想显示),最后再次加载默认页面。下面是我的代码: HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="format-d
<!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;
}
}
通知函数(e){
开关(如事件)
{
“已登记”案件:
打破
案例“信息”:
如果(如前景)
{//如果应用程序位于前台,则状态栏通知
navigator.notification.beep(1);
}
其他的
{//单击状态栏通知后
$.mobile.changePage(“#聊天”);
}
//应用程序打开时的通知
打破
案例“错误”:
//$(“#应用程序状态ul”).append(“错误->消息:”+e.MSG+“ ”);
打破
违约:
//$(“#应用程序状态ul”).append(“事件->未知,收到了一个事件,我们不知道它是什么”);
打破
}
}
所以它显示欢迎页面,进入聊天页面,然后再次返回欢迎页面。试图设置超时,但没有帮助
有什么解决方案吗?请查看它是否对您有帮助,我在phonegap android中使用了此代码,它工作正常。另外,请检查jquery mobile 1.4中的$.mobile.changePage是否已弃用
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");
}
}
谢谢@Ashokbharathi,我的代码中有这个问题。我调用了document.addEventListener(“online”,onOnline,false),默认情况下,每次重定向到欢迎页面时都会调用它。