handling back button in android from jquery

前端 未结 2 1025
既然无缘
既然无缘 2021-01-25 08:51

We have developed an application in jQuery integrated with android (which has only one activity). From this activity we are loading an HTML file, on this file we are showing and

相关标签:
2条回答
  • 2021-01-25 09:05

    Use this code in your HTML page to handle back button pressed

    document.addEventListener("backbutton", onBackKeyDown, false);
    
    function onBackKeyDown() {
    // Handle the back button
    }
    
    0 讨论(0)
  • 2021-01-25 09:18

    Try this:

    function onDeviceReady() {
        // Add this line to the on onDeviceReady() function
        document.addEventListener("backbutton", onBackKeyDown, false);
    }
    
    // Handle back button hardware
    function onBackKeyDown(e) {
        e.preventDefault(); // the default action of the event e should not be triggered. 
        history.back(1); // load the previous window.location
    }
    
    0 讨论(0)
提交回复
热议问题