简体   繁体   English

如何在离子的inAppBrowser内的后退按钮上添加确认弹出窗口

[英]How to add confirmation popup on back button inside inAppBrowser in ionic

I have added an inAppBrowser and now after going inside the browser,我添加了一个 inAppBrowser,现在进入浏览器后,

Expectation : if i click the hardware back button, i want to show a confirmation popup with option leave page and Cancel期望如果我单击硬件后退按钮,我想显示一个带有选项离开页面和取消的确认弹出窗口

Actual : It is calling the Exit event and closing the inAppBrowser实际它正在调用 Exit 事件并关闭 inAppBrowser

in my x.ts file :在我的 x.ts 文件中:

this.inAppBrowser.on('exit').subscribe(
    () => {
      this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
      console.log('orientation after browser close: ' + this.screenOrientation.type);
    }
  );

My issue is that, do we have any way or workaround to detect backbutton click instead of exit ?我的问题是,我们是否有任何方法或解决方法来检测后退按钮点击而不是退出?

According to documentation plugin has its own logic for the hardware back button:根据文档插件有自己的硬件后退按钮逻辑:

hardwareback : set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. hardwareback : 设置为 yes 以使用硬件后退按钮在 InAppBrowser 的历史记录中向后导航。 If there is no previous page, the InAppBrowser will close.如果没有上一页,InAppBrowser 将关闭。 The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser.默认值为 yes,因此如果您希望后退按钮只是关闭 InAppBrowser,则必须将其设置为 no。

So, the answer - no.所以,答案 - 不。 You do have not the possibility to set up the logic for the back button inside the Ionic application.您无法在 Ionic 应用程序中设置后退按钮的逻辑。 But you can fork this plugin, implement this feature and use it.但是你可以 fork 这个插件,实现这个功能并使用它。

I suggest creating a dedicated page where you open the inappbrowser (ngOnInit).我建议创建一个专用页面,您可以在其中打开 inappbrowser (ngOnInit)。 This page should be full-screen with the question "Are you sure you want to exit?"此页面应该是全屏的,并带有“您确定要退出吗?”的问题。 and 2 buttons "Yes" / "No".和 2 个按钮“是”/“否”。 If the user presses on "Yes" exit the app, if the user presses "No" reopen the inappbrowser.如果用户按“是”退出应用程序,如果用户按“否”重新打开应用程序浏览器。 This way if the inappbrowser is closed, it will show the dedicated page, that acts as your confirmation button...这样,如果 inappbrowser 关闭,它将显示专用页面,作为您的确认按钮...

Sorry but the code won't work.抱歉,代码不起作用。

Edit编辑

this.platform.backButton.subscribeWithPriority(100, () => {
    if (window.confirm('Are you sure you want to exit, amigo?')){
      navigator['app'].exitApp();
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM