How do I close window from javascript which was opened by Ionic Capacitor

Viewed 1350

I am opening window in my ionic app

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

But then I want to close close that window it self when user complete certain action. I tried window.close but due to security issues it does not work.

How do I close that window?

1 Answers

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();
    }
  });
}
Related