コードバを使用してハイブリッドモバイルアプリケーションを作成しています。これは初めてのことです。コードバを使用したハイブリッドモバイルアプリケーションのバックボタン機能の処理方法
ここで、ユーザーがホームページで戻るボタンを2回クリックしても、戻るボタンの機能を処理できない場合、アンドロイドアプリを終了します。
いずれかが特定のページのためのボタンの機能をバック処理する方法を教えてもらえます
これは私のindex.htmlである
<!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>
これは私のIndex.jsです:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener("backbutton", function() {
if ($('.ui-page-active').attr('id') == 'main') {
exitAppPopup();
} else {
history.back();
}
}, false);
},
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
},
function exitAppPopup() {
navigator.notification.confirm(
'Exit PhoneGap ' + device.cordova + ' Demo?'
, function(button) {
if (button == 2) {
navigator.app.exitApp();
}
}
, 'Exit'
, 'No,Yes'
);
return false;
}
};
app.initialize();
コンソールにエラーがありますか? – Rayon
コンソールにエラーはありません。私はリンクをたどっていました - > http://ventusmoso.com/phonegap/jquerymobile/add-an-exit-menu-to-mobile-app-built-in-phonegap-and-jquery-モバイル/チュートリアル。私はどんな答えも得ていません – lakshmansundeep
アラートを入れて、どこが壊れているのかを試してみてください... – Rayon