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