backbutton event not working on Intel XDK Crosswalk app

末鹿安然 提交于 2019-12-13 01:33:00

问题


I put code below in my XDK project. I use onsenUI and Angular. Everything works great in the emulator but the Crosswalk app doesn't trigger this during backbutton event.

Is there anything else that needs to be done? I can't find anything specific about this in the documentation. Thanks.

<script src="cordova.js" type="text/javascript"></script>
<script>
    document.addEventListener ("backbutton", onBackKeyDown, false);

    function onBackKeyDown () {

        // Handle the back button
        console.log("back");
        //other codes here
    }
</script>

回答1:


It turns out you need to have this complete triggers for it to work:

// Wait for device API libraries to load
        //
        function onLoad() {
           document.addEventListener("deviceready", onDeviceReady, false);
        }

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

        // Handle the back button
        //
        function onBackKeyDown() {
           // Handle the back button
        }



回答2:


You can use this function directly to intercept back button

document.addEventListener("intel.xdk.device.hardware.back", function() {

         // write your code
    }, false);


来源:https://stackoverflow.com/questions/24073019/backbutton-event-not-working-on-intel-xdk-crosswalk-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!