Let PhoneGap return key exit application need to confirm effect again

Source: Internet
Author: User

I've been working on a WebApp project recently, encountered the problem of exit, in order to improve the user experience, the intention to press the return key after the user needs to confirm again to quit, search on the internet, found that a lot of the need for a variety of plug-ins, for such a simple function, if the introduction of a plug-in is obviously not worth it, Finally kung fu, I still found a very good code, recorded.

Document.addeventlistener ("Deviceready", Ondeviceready, false);

function Ondeviceready () {
Registering the Fallback button event listener
Document.addeventlistener ("Backbutton", Onbackkeydown, false);
}

Return key
function Onbackkeydown () {
Navigator.notification.confirm (
' Press OK to exit the program! ',//message
Onconfirm,//callback to invoke with index of button pressed
' Are you sure you want to quit the program? ',//title
' OK, Cancel '//Buttonlabels
);
}

function onconfirm (button) {
if (button==1) navigator.app.exitApp (); Select OK to perform exit
}

If you are in need of such a function, quickly take the past to use it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.