Search code examples
angularionic-frameworkionic3inappbrowserionic-native

Ionic Mobile application navigate to external url


I have a ready Web Application by using ASP.Net Web Forms. Now I want to use the content of my web application in my mobile application. and my mobile application with login screen.

I build my mobile application by using ionic. In my mobile application consist of Login screen only. After user login,application with navigate to external url of my web application by using inappbrowser

Now my problem is when user click back button in mobile, my application with back to login screen. Can I make it like when user click back button, the application exit the application without navigate back to login page

The following is my code

  public login() {

    this.auth.login(this.registerCredentials).subscribe(data => {
        const browser = this.iab.create('https://demos.devexpress.com/DashboardFinancialDemo/','_blank',{location:'no', zoom:'no'}); 
        browser.show();
    },
    error => {
      this.showError(error);
    });
  }

Solution

  • You can listen to InAppBrowser events, so simply when exit is triggered for the browser, exit the app.

    import { Platform } from 'ionic-angular';
    
    // ....
    
    constructor(private platform: Platform) { }
    
    public login() {
      this.auth.login(this.registerCredentials).subscribe(data => {
        const browser = this.iab.create('https://demos.devexpress.com/DashboardFinancialDemo/','_blank',
                        {location:'no', zoom:'no'}); 
        browser.show();
        // add this!
        browser.on('exit').subscribe((event) => {
          this.platform.exitApp();
        });
      },
      error => {
        this.showError(error);
      });
    }