Javascript 如何使用cordova处理混合移动应用程序的后退按钮功能
我正在使用cordova创建混合移动应用程序,对此我是新手 在这里,我想退出android应用程序,如果用户在主页上点击后退按钮两次,但我无法处理后退按钮功能 有人能告诉我如何处理特定页面的后退按钮功能吗 这是我的index.htmlJavascript 如何使用cordova处理混合移动应用程序的后退按钮功能,javascript,android,jquery,html,cordova,Javascript,Android,Jquery,Html,Cordova,我正在使用cordova创建混合移动应用程序,对此我是新手 在这里,我想退出android应用程序,如果用户在主页上点击后退按钮两次,但我无法处理后退按钮功能 有人能告诉我如何处理特定页面的后退按钮功能吗 这是我的index.html <!DOCTYPE html> <html> <head> <meta name="format-detection" content="telephone=no"> &l
<!DOCTYPE html>
<html>
<head>
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<title>Hello World</title>
</head>
<body>
<div id="main" data-role="page">
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
函数ondevicerady()
{
if(navigator.userAgent.match(“Android”))
{
document.addEventListener(“backbutton”,onBackKeyDown,true);
}
}
函数onBackKeyDown(e)
{
if(window.location.hash==“#您的页面名称”)
{
navigator.app.exitApp();
}
否则
{
window.history.back();
}
}
试试这个:
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#homepage')){
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);
console中有错误吗?console中没有错误。我遵循了链接-->教程,但没有。我没有得到任何回答,试着把警报和测试放在哪里。。。
<script type="text/javascript" src="cordova.js"></script>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
if (navigator.userAgent.match("Android"))
{
document.addEventListener("backbutton", onBackKeyDown, true);
}
}
function onBackKeyDown(e)
{
if (window.location.hash === "#You page name")
{
navigator.app.exitApp();
}
else
{
window.history.back();
}
}
document.addEventListener("backbutton", function(e){
if($.mobile.activePage.is('#homepage')){
navigator.app.exitApp();
}
else {
navigator.app.backHistory()
}
}, false);