在 Phonegap InAppBrowser 上处理 Android 后退按钮 [英] Handle Android Back Button on Phonegap InAppBrowser

查看:34
本文介绍了在 Phonegap InAppBrowser 上处理 Android 后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 InAppBrowser 上导航页面时禁用或覆盖 Android 后退按钮.我可以添加一个可以处理的事件侦听器吗?

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?

查看@T_D 下面提供的解决方案的答案是我能得到的最接近的答案.似乎不可能覆盖 InAppBrowser 中的按钮,因为在此插件上导航页面时所有 PhoneGap 调整都停止工作.除了修改 API 库之外,我找不到任何其他解决方案.如果这里有任何 PhoneGap 人并且了解更多信息,我会很高兴得到一些评论.谢谢.

Looking at the answer by @T_D below the solutions provided are the closest I could get to. It does not seem to be possible to override the button in InAppBrowser as all the PhoneGap tweaks stop working while navigating pages on this plugin. I was not able to find any other solution rather than modifying the API library. If there are any PhoneGap guys here and know something more, I 'll be glad to get some comment. Thanks.

我得到的最近的:

var ref = window.open('http://apache.org', '_blank', 'location=yes');
ref.addEventListener("backbutton", function () { })

推荐答案

根据文档 现在可以为 InAppBrowser 配置硬件后退按钮的行为:

According to the documentation the behaviour of the hardware back button can be configured now for the InAppBrowser:

hardwareback:设置为 yes 以使用硬件后退按钮在 InAppBrowser 的历史记录中向后导航.如果没有上一页,InAppBrowser 将关闭.默认值为 yes,因此如果您希望后退按钮简单地关闭 InAppBrowser,则必须将其设置为 no.

hardwareback: set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. If there is no previous page, the InAppBrowser will close. The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser.

感谢克里斯·埃里克森.

因此,如果向后导航是所需的行为,只需更新您的 InAppBrowser 插件.

So just update your InAppBrowser plugin if the backward navigation is the desired behaviour.

更多详情参见:https://github.com/apache/cordova-plugin-inappbrowser/pull/86

这篇关于在 Phonegap InAppBrowser 上处理 Android 后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆