问题
I put code below in my XDK project. I use onsenUI and Angular. Everything works great in the emulator but the Crosswalk app doesn't trigger this during backbutton event.
Is there anything else that needs to be done? I can't find anything specific about this in the documentation. Thanks.
<script src="cordova.js" type="text/javascript"></script>
<script>
document.addEventListener ("backbutton", onBackKeyDown, false);
function onBackKeyDown () {
// Handle the back button
console.log("back");
//other codes here
}
</script>
回答1:
It turns out you need to have this complete triggers for it to work:
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
}
// Handle the back button
//
function onBackKeyDown() {
// Handle the back button
}
回答2:
You can use this function directly to intercept back button
document.addEventListener("intel.xdk.device.hardware.back", function() {
// write your code
}, false);
来源:https://stackoverflow.com/questions/24073019/backbutton-event-not-working-on-intel-xdk-crosswalk-app