gpt4 book ai didi

javascript - PhoneGap 后退按钮退出应用程序

转载 作者:太空宇宙 更新时间:2023-11-04 12:44:47 26 4
gpt4 key购买 nike

目前我正在使用 PhoneGap (Cordova 2.2)、JQuery 和 Javascript 开发移动应用程序。登陆页面是登录页面。因此,一旦我使用登录凭据进入仪表板页面,当我单击 BACK BUTTON 时,它会返回登录页面,而不是停留在仪表板页面上。我能做些什么???欢迎提出建议。

我试过了,

脚本

<head>
<script type="text/javascript" charset="utf-8" src="cordova-2.2.0.js"></script>
<script type="text/javascript" charset="utf-8">

// Call onDeviceReady when Cordova is loaded.
//
// At this point, the document has loaded but cordova-2.2.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}

// Cordova is loaded and it is now safe to call Cordova methods
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}

// Handle the back button
//
function onBackKeyDown() {
alert("Back Button Clicked"); //called the alert..checking
}

</script>

HTML

<body onload="onLoad()">
</body>

我的 onDeviceReady 和 onBackKeyDown 功能不工作/已触发。我错过了什么吗???

最佳答案

尝试使用 loggin 变量来检查是否登录并在回调函数上做一些事情。

function onBackKeyDown(evt) {
evt.preventDefault();
evt.stopPropagation();
if(loggedin=='yes'){
//dont do anything or show popup
}else{
history.back();
}
}

需要先绑定(bind)eventLinstener,在页面onLoad OR $(document).ready()方法中调用app.initialize()

 var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},

// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {

document.addEventListener('deviceready', this.onDeviceReady, false);

},

onDeviceReady: function() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
};

关于javascript - PhoneGap 后退按钮退出应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26601843/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com