Ionic hybrid app - close window from server


#1

I am building an ionic hybrid app. the native app is a simple one page (setting page) with ‘go to app’ button (it will have login credentials in the future).

The ‘go to app’ button opens by window.open(,’_self’).

window.open('http://127.0.0.1:8991/gringo/index.html#/home', '_self', 'location=yes');

The app on the server is also build with ionic.

I want to close the ‘window’ from the server and get back the the ‘settings page’ on the native app.

I’ve tried so many things for the past 4 hours, and ended with no success.

Any suggestion on how it can be done?

Has anyone encountered this issue?

Thanks in advance.


#2

you should have a redirect in you backendpage to a page you can identify as “please close my app” something like a unique url like:
http://127.0.0.1:8991/gringo/close

in your app

var externalPaymentWindow = $window.open('URL', '_blank', 'location=yes,enableViewportScale=yes');
// everytime a new site is loaded
externalPaymentWindow.addEventListener('loadstart', function (event) {
  // current windowurl
  var url = event.url;
  // check if current url contains close
  if (url.indexOf('/close') !== -1) {
    // close window
    externalPaymentWindow.close();
  }
});