" [未定义]不是一个函数"在PhoneGap的处理后退按钮事件时, [英] "[undefined] is not a function" when handling backbutton event in PhoneGap
问题描述
我想从的 PhoneGap的文档和<一href="http://stackoverflow.com/questions/9631933/override-android-backbutton-behavior-only-works-on-the-first-page-with-phonegap">Override Android的后退按钮的行为只能与PhoneGap的中的第一页。
我的code:
&LT;脚本&GT;
document.addEventListener(deviceready,onDeviceReady,假);
传播onDeviceReady(){
警报(东风);
的console.log(PhoneGap的准备好了!);
document.addEventListener(后退按钮,handleBackButton,假);
}
传播handleBackButton(){
的console.log(后退按钮pressed!);
警报(东风);
}
&LT; / SCRIPT&GT;
不过,我得到这个错误:
05-21 16:00:03.248:E / Web控制台(1615年):类型错误:对前pression'PhoneGap.fireDocumentEvent[未定义]结果是不是一个函数。在不确定的:1
请检查您是否连接正确的PhoneGap,x.js为平台,javascript的code是为Android,IOS等不同。
在后退按钮是pssed在Android的$ P $,事件后退按钮被解雇了,所以如果你想回去导航历史,你应该做的是安装下面的处理程序,以它:
document.addEventListener(后退按钮,功能(五){
即preventDefault();
navigator.app.backHistory();
}, 真正);
I am trying to work with the back button with help from the PhoneGap Documentation and Override Android Backbutton behavior only works on the first page with PhoneGap.
My code:
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("df");
console.log("PhoneGap Ready!");
document.addEventListener("backbutton", handleBackButton, false);
}
function handleBackButton() {
console.log("Back Button Pressed!");
alert("df");
}
</script>
But I get this error:
05-21 16:00:03.248: E/Web Console(1615): TypeError: Result of expression 'PhoneGap.fireDocumentEvent' [undefined] is not a function. at undefined:1
Check that you are linking the correct phonegap-x.js for the platform, the javascript code is different for android, iOS, etc.
When the back button is pressed in Android, the event 'backbutton' is fired, so if you want to go back in the navigation history, what you should do is attaching the following handler to it:
document.addEventListener("backbutton", function(e){
e.preventDefault();
navigator.app.backHistory();
}, true);
这篇关于&QUOT; [未定义]不是一个函数&QUOT;在PhoneGap的处理后退按钮事件时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!