![](/img/trans.png)
[英]App Exit NOT working on pressing the back button in Android App (Phonegap & AngularJS)
[英]Button long press to exit the app on Android PhoneGap
我有以下代碼:
function logout_now()
//Logout of the app after a long press onKey(Longer then 5 sec) Not working correctly
{
var startTime;
var endTime;
var TimeDiff;
document.getElementById('Exit_btn').addEventListener('touchstart',function(event)
{startTime = new Date().getTime();
},false);
document.getElementById('Exit_btn').addEventListener('touchend',function(event){
endTime = new Date().getTime();
TimeDiff = endTime-startTime;
if( endTime-startTime > 5000 ) //logout after more then 5 Second = 5000 mSec
{
logout();
}
},true);
}
當用戶等待5秒(長按)后按下Exit_btn時,它將啟動以下功能:
函數logout(){
var password = prompt("Please enter the exit password");
if (password == "123")
{
alert("Goodbye");
navigator.app.exitApp();
}
else
{
alert("Wrong Password!");
console.log("index.html");
}
}
問題在於它無法正常運行,這意味着如果我輸入了錯誤的密碼,提示框將繼續彈出,或者如果我終於正確退出了應用程序,則當我再次啟動它時,它會崩潰。
有人可以在這里看到問題嗎? 為什么會發生?
任何幫助表示贊賞。
謝謝。
您可以使用jQuery Mobile Taphold事件,如下所示...這可能對您有幫助...
HTML:
<div id="logout-btn">Logout</div>
jQuery Mobile:
$(function() {
$( "#logout-btn" ).on('taphold', tapholdCallBack);
// Callback function
function tapholdCallBack(ev) {
logout();
.....
}
});
要么
$(document).delegate('div[data-role*="page"]', 'pageshow', function () {
$(document).delegate('#logout-btn', 'taphold', function (ev) {
logout();
});
});
長按注銷按鈕750毫秒,它將調用logout()。
默認情況下,抽頭持續時間為750ms,如果您想通過將值分配to $.event.special.tap.tapholdThreshold
更改抽頭應花費的時間。 如下圖所示
$(document).bind("mobileinit", function () {
$.event.special.tap.tapholdThreshold = 5000,
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.