cordova - Override Android Backbutton behavior only works on the first page with PhoneGap -
i using phonegap 1.5.0, jquery 1.7.1 , jquery mobile 1.0.1 , trying override backbutton in android stated here or here.
document.addeventlistener("deviceready", ondeviceready, false); // phonegap loaded function ondeviceready() { console.log("phonegap ready!"); // waiting button document.addeventlistener("backbutton", handlebackbutton, false); } // handle button function handlebackbutton() { console.log("back button pressed!"); navigator.app.exitapp(); }
but works on first page of app. after changing different page backbutton nothing @ all. app consists of tabview this:
<body> <div data-role="page" id="pilottab"> <div data-role="header"> <h1>pilot</h1> </div> <div data-role="content" id="pilotcontent"> content 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 stupid mistake or there special have consider make work properly? in advance.
i gone through new phonegap source code , did following changes make backbutton work.
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>
put following code in 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]); }
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) { (var in data) { e[i] = data[i]; } } document.dispatchevent(e); return; }
i have put whole cordova-1.5.0.js in gist updated code https://gist.github.com/2020325
though working me still may need changes work in possible scenarios.
edit
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) { (var in data) { e[i] = data[i]; } } document.dispatchevent(e); return; }
Comments
Post a Comment