Handle Android Back Button on Phonegap InAppBrowser

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

    EDIT NOTE: As far as I know, it's not possible to override the back-button for the InAppBrowser in PhoneGap. But I did my best searching for possible solutions...

    There's an eventListener to override back-button in PhoneGap -doesn't work for InAppBrowser-

    function onDeviceReady(){
        document.addEventListener("backbutton", onBackKeyDown, false);
    }
    

    Alternative eventListener to override back-button -the OP said this didn't work either-

    var ref = window.open('http://www.stackoverflow.com', '_blank', 'location=yes');
    ref.addEventListener("backbutton", function () {
        //logic here
    })
    

    Overriding the Back-button in an Activity -this is plain java, obviously didn't work in PhoneGap-

    @Override
    public void onBackPressed()
    {
       //logic here
    }
    

    Conclusion:

    Above solutions didn't work, following links (this answer, this one and a third one) didn't help either. So it's highly possible that overriding the back-button for the InAppBrowser in PhoneGap is not possible. If someone does come up with a solution or if things changed for a new PhoneGap version feel free to let us know...

    EDIT:

    Installing this plugin may take you to closest solution:

    cordova plugin add org.apache.cordova.inappbrowse
    

    What this plugin will do, in WP8, it will overlay back/forward/close button on InAppBrowser whenever you open any link/page in it.

    See this image: enter image description here

提交回复
热议问题