我使用PhoneGap的1.5.0,jQuery的1.7.1和jQuery移动1.0.1,并试图覆盖在Android上的后退按钮作为陈述的这里或here.
I am using PhoneGap 1.5.0, jQuery 1.7.1 and jQuery mobile 1.0.1 and trying to override the backbutton in Android as stated here or here.
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap loaded
function onDeviceReady() {
console.log("PhoneGap Ready!");
// waiting for button
document.addEventListener("backbutton", handleBackButton, false);
}
// handle the back button
function handleBackButton() {
console.log("Back Button Pressed!");
navigator.app.exitApp();
}
但它仅适用我的应用程序的第一页上。切换到不同的页面后,后退按钮做什么都没有。该应用程序包含这样一个TabView的的:
But it only works on the first page of my app. After changing to a different page the backbutton does nothing at all. The app consists of a tabview like this:
<body>
<div data-role="page" id="pilotTab">
<div data-role="header">
<h1>Pilot</h1>
</div>
<div data-role="content" id="pilotContent">
content be here ;)
</div>
<div data-role="footer" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a href="pilotTab.html" data-transition="none">Lotse</a>
</li>
<li><a href="bookingTab.html" data-transition="none">Verkehr</a>
</li>
<li><a href="mainListTab.html" data-transition="none">Bört</a>
</li>
</ul>
</div>
<!-- /navbar -->
</div>
<!-- /footer -->
</div>
这是个愚蠢的错误或者是有一些特别的东西我要考虑,使其正常工作?先谢谢了。
Is it a stupid mistake or is there something special I have to consider to make it work properly? Thanks in advance.
我通过新的PhoneGap源$ C $ C不见了,也以下更改,使后退按钮的工作。
I gone through the new Phonegap source code and did following changes to make the backbutton work.
HTML测试code
Html test code
<script type="text/javascript">
$("#home").click(function(){
$.mobile.changePage("home.html");
});
document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("backbutton", handleBackButton, false);
function onDeviceReady() {
console.log("PhoneGap Ready!");
}
function handleBackButton() {
console.log("Back Button Pressed!");
navigator.app.exitApp();
}
</script>
将下面的code。在 document.addEventListener
的其他
块科尔多瓦-1.5.0.js
后线没有507
Put the following code in the else
block of document.addEventListener
in cordova-1.5.0.js
after line-no 507
if (e === 'backbutton') {
var exec = require('cordova/exec')
exec(null, null, "App", "overrideBackbutton", [true]);
}
将以下code在科尔多瓦
定义 fireDocumentEvent
方法 cordova- 1.5.0.js
后线没有592
Put following code in fireDocumentEvent
method of cordova
definition in cordova-1.5.0.js
after line-no 592
if(type == "backbutton"){
var e = document.createEvent('Events');
e.initEvent(type);
if (data) {
for (var i in data) {
e[i] = data[i];
}
}
document.dispatchEvent(e);
return;
}
我已经把整个科尔多瓦 - 1.5.0.js在这个要点与更新code HTTPS://gist.github。 COM / 2020325
尽管这是为我工作,但它仍然可能需要一些变化,所有可能的方案工作。
Though it is working for me but it still may need some changes to work in all the possible scenarios.
将以下code在科尔多瓦
定义 fireDocumentEvent
方法 cordova- 1.5.0.js
后线没有592
Put following code in fireDocumentEvent
method of cordova
definition in cordova-1.5.0.js
after line-no 592
if(type == "backbutton" || type == "menubutton" || type == "searchbutton"){
var e = document.createEvent('Events');
e.initEvent(type);
if (data) {
for (var i in data) {
e[i] = data[i];
}
}
document.dispatchEvent(e);
return;
}