Handle Android Back Button on Phonegap InAppBrowser

后端 未结 9 724
小鲜肉
小鲜肉 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:11

    As far as I know it's not possible to override or detect the back button from inAppBrowser. When you press the back button, inAppBrowser will hide and return control to the Phonegap page. You can catch this with the focus event on the window, (using jQuery) like

    var browser = window.open('http://example.com', '_blank', 'location=no');
    $(window).on('focus', function() {
        browser.show();
    });
    

    to reopen the browser. You could then use browser.executeScript() to signal the webapp loaded in the browser, if you like.

    Inspired by this forum post.

提交回复
热议问题