Handle Android Back Button on Phonegap InAppBrowser

后端 未结 9 727
小鲜肉
小鲜肉 2020-12-09 21:41

I would like to disable or override the Android Back button while I am navigating pages on the InAppBrowser. Can I add an event listener that can handle that?

9条回答
  •  抹茶落季
    2020-12-09 22:05

    I know this question has an answer already but I post my answer for those who any of these answers didn't work for them(such as myself):

    so I have a multi page app for android and IOS and I am using cordova 5.x and I added the code below in every page except the page I needed InAppBrowser:

    delete window.open;
    

    and then for the rest of the pages I used:

    document.addEventListener("backbutton", onBackKeyDown, false);
    function onBackKeyDown(event) {
    // your code for handling back button comes here
    }
    

    for handling back button

    note that: delete window.open; base on the documentation

    manually restore the default behaviour of 'window.open'

    after that InAppBrowser plugin worked great and I handled back button in all pages correctly.

    one last thing don't forget to add: in pages you need to have InAppBrowser.

    hope this help.

提交回复
热议问题