首页 > 解决方案 > 如何从 Ionic Capacitor 打开的 javascript 关闭窗口

问题描述

我在我的离子应用程序中打开窗口

 await Browser.open({url: environment.apiUrl + `/myurl`});

但是当用户完成某些操作时,我想关闭它自己的窗口。我试过window.close了,但由于安全问题,它不起作用。

我如何关闭那个窗口?

标签: angularionic-frameworkionic-nativecapacitor

解决方案


Finally found the way.

  • Register custom scheme
  • In external app redirect window.location.href="customschema://"
  • For iOS listen for appUrlOpen and close browser, for android as soon as you redirect to custom schema will close.

Place into app.component on app start

if (this.platform.is('ios')) {
  App.addListener('appUrlOpen', data => {
    if (data.url.indexOf('comflymarkonline://')> -1) {
      Browser.close();
    }
  });
}

推荐阅读