0
我有以下代碼:按鈕長按退出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函數註銷() {
var password = prompt("Please enter the exit password");
if (password == "123")
{
alert("Goodbye");
navigator.app.exitApp();
}
else
{
alert("Wrong Password!");
console.log("index.html");
}
}
的麻煩的是,它不能順利運行,這意味着如果我輸入了錯誤的密碼,提示框不斷彈出,或者如果我終於正常退出應用程序,那麼當我再次啓動應用程序時,它會崩潰。
任何人都可以在這裏看到問題嗎?爲什麼會發生?
任何幫助表示讚賞。
謝謝。
謝謝你的回答。我試圖實現這一點,但不幸的是,logout()函數從未被調用過。我不明白爲什麼.. – OlejkaKL 2013-04-10 11:34:16
@ user1756004:你的logout()函數只是沒有得到調用,或者taphold事件回調函數本身沒有被調用..? – 2013-04-10 12:02:46
taphold事件回調函數沒有被調用。我在那裏設置了一個警報,它沒有反應。 – OlejkaKL 2013-04-10 12:18:18