Opening all links in in-app-browser?

Hello i’m trying to open all links in the in app browser. I tried the solutions in this topic:

But it’s still not working.

My current code:

import {Component, ViewChild} from '@angular/core';
import {Platform} from 'ionic-angular';
import {NavController} from 'ionic-angular';
import {OneSignal} from '@ionic-native/onesignal';
import {InAppBrowser} from '@ionic-native/in-app-browser';

declare var window: any;

@Component({
    templateUrl: 'app.html',
    providers: [InAppBrowser]
})

export class MyApp {
        @ViewChild(NavController) navCtrl: NavController;

    constructor(public platform: Platform, private oneSignal: OneSignal, private inAppBrowser: InAppBrowser) {
        platform.ready().then(() => {

           //Check if the app isn't run in a browser.
            if (this.platform.is('core') || this.platform.is('mobileweb')) {
                // Do not use cordova services
            } else {
window.open = (url, target?, opts?) => new inAppBrowser(url, target, opts);
            }
        });
    }
}

The new inAppBrowser(url, target, opts); is red underlined in my IDE.
The error I get is: ‘Cannot use ‘new’ with an expression whose type lacks a call or construct signature.’

Does anyone know what I can do to fix it? I’m running the latest version of Ionic.

I also tried using: window.open = cordova.inAppBrowser.open;
But then the links don’t work at all.

Fixed it by using this tutorial and making it a service.

https://www.youtube.com/watch?v=SPJ9TdHaI3A

Can you please give the code you use?

2 Likes

+1 for me, need it too