我在使用Ripple Emulator的Cordova 2.8
Android项目的最初页面加载时遇到了angular-mobile-nav的问题.我得到的错误是:
TypeError: Object #<Object> has no method 'overrideBackbutton' at module.exports.exec (chrome-extension://geelfhphabnejjhdalkjhgipohgpdnoc/ripple.js:40:22917) at backButtonChannel.onHasSubscribersChange (http://localhost:8076/cordova.js:1145:13) at Channel.subscribe (http://localhost:8076/cordova.js:667:49) at HTMLDocument.document.addEventListener (http://localhost:8076/cordova.js:132:34) at null.<anonymous> (http://localhost:8076/components/mobile-nav/mobile-nav.js:11:14) at Channel.fire (http://localhost:8076/cordova.js:709:23) at http://localhost:8076/cordova.js:232:47
基本上,它是由mobile-nav.js第11行引起的:
document.addEventListener(“backbutton”,function(){
而来自第1145行的cordova.js电话引发的错误:
exec(null,null,“App”,“overrideBackbutton”,[this.numHandlers == 1]);
这是一个可以复制的问题吗?任何帮助将不胜感激.
解决方法
我在第一次使用Ripple和Phonegap 2.5.0时遇到过这种情况.正如你所指出的,在Android的cordova-2.8.0.js的第1145行,它假定在Android平台上运行,因此调用本机函数App.overrideBackbutton(),其中Ripple没有存根.
因为它只是在附加/分离第一个处理程序时调用它,所以我通过欺骗Ripple认为已经存在多个处理程序来解决这个问题:
<html> <head> <script type="text/javascript" charset="utf-8" src="cordova-2.8.0.js"></script> <script type="text/javascript" charset="utf-8" src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> _IS_RIPPLE_EMULATOR = $('#tinyhippos-injected').length > 0; function deviceready() { // Make ripple think that a back button handler has already been attached if(_IS_RIPPLE_EMULATOR) cordova.addDocumentEventHandler('backbutton'); document.addEventListener("backbutton",function(){ alert("Pressed back"); }); } document.addEventListener("deviceready",deviceready,true); </script> </head> <body></body> </html>