我按照 deviceready
事件后 false
参数附加事件监听器 backbutton
的文档覆盖了我的设备后退按钮 .
我是这样做的:
// Smart App object
define([
'routes',
'cordova',
'angular',
'angularRoute',
'angularResource',
'angularTouch',
'config',
'controllers',
'services',
'directives',
'helpers'
], function(appRoute) {
var oApp = {
_app: {},
init: function() {
console.log('init');
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
console.log('ok device ready');
document.addEventListener('backbutton', function() {
console.error('deviceback start');
angular.element('.ng-scope').scope().back();
console.error('deviceback end');
}, false);
// ...
}
// ...
我疯狂地想弄清楚为什么按下设备按钮没有触发我附加的这个 backbutton
事件,我甚至没有在控制台中看到 console.error
消息 . 我现在正在Android上测试我还没有't tested on any of the other Phone OS' .
console.log('ok device ready')
确实触发并且我的应用程序正常工作,设备 backbutton
被覆盖,因为它的默认功能没有发生,但是如上所述,我的功能也没有发生 .
我读了其他stackoverflow topcis并且他们说Cordova版本获得了修复,但我的Cordova版本远远超过他们的版本,我的 .cordova/config.json
文件告诉我:
{
"lib": {
"www": {
"id": "com.tigoenergy.smart",
"version": "3.5.0"
}
}
}
它是 3.5
然后我的 info.txt
告诉我它是 5.0.0
:
Node version: v0.10.25
Cordova version: 5.0.0
Config.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- config.xml reference: https://build.phonegap.com/docs/config-xml -->
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
有没有人有任何想法?
3 回答
尝试使用正常使用cordova事件的方式 .
官方文件here
修改代码
很少有参考链接here和here
问题是我在iframe中导入cordova.js,即使它已经在父窗口范围内 . 我不知道它会破坏它,并认为我必须在iframe中导入cordova.js . 从iframe中删除修复它 .
试试这个
确保这些文件在您的页面中是链接