简体   繁体   English

禁用phoneGap中的后退按钮单击

[英]Disable backbutton click in phoneGap

I'm trying to disable back button press so the app does not close as my app is a single page app.. 我正在尝试禁用后退按钮的按下,因此该应用程序无法关闭,因为我的应用程序是单页应用程序。

i read that you need to wait for deviceready event, and if i look at the console im receiving that event. 我读到您需要等待deviceready事件,如果我看着控制台即时消息接收到该事件。 (BUT from another location i suspect its hidden in the templated and cant find out how to apply my functions to that) Received Event: deviceready (但是从另一个位置我怀疑其隐藏在模板中,无法找到如何将其应用到该模板中)接收到的事件:deviceready

problem is that im just not receiving anything and my app just closes when the i press the back button. 问题是即时消息我什么也没收到,而我按后退按钮时我的应用程序只是关闭了。 and i think im receiving the deviceready from somewhere else build in by adobe in the template i used for my app.. 我认为即时通讯从其他地方接收到设备的就绪信息,这是Adobe在我用于我的应用程序的模板中建立的。

so none of the functions are getting fired thats why i tend to believe i need to place this somewhere else 所以没有功能被解雇,这就是为什么我倾向于认为我需要将其放置在其他地方的原因

<script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
    app.initialize();
     function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
    alert('gege');
}

// device APIs are available
//
function onDeviceReady() {
    // Register the event listener
    document.addEventListener("backbutton", onBackKeyDown, false);
    alert('gege');
}

// Handle the back button
//
function onBackKeyDown() {
alert('backbuttonpressed');
}
    </script>

Try 尝试

document.addEventListener("deviceready", onDeviceReady, false);
document.addEventListener("backbutton", onBackKeyDown, false);
app.initialize();

function onDeviceReady(){        

}

function onBackKeyDown(event) {
    event.preventDefault();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM