How to open link EXTERNALLY

I don’t want the in app browser to open, I want it to open in safari/chrome

2 Likes

You can open it using the inAppBrowser plugin,
you can have it here

cordova plugin add cordova-plugin-inappbrowser

You then import it in .ts file
import {InAppBrowser} from 'ionic-native';

Or if you have native 3.x import in ionic native 3.x
import { InAppBrowser } from '@ionic-native/in-app-browser';

use this
let browser = new InAppBrowser('url', '_system'); //For system browser, you'll be prompt to choose your browser if you have more than one let browser = new InAppBrowser('url', '_blank'); //For webview,

get more information here http://ngcordova.com/docs/plugins/inAppBrowser/

3 Likes

Hey, not OP but this don’t seem to work for me.

Ionic version 2.2.1

I am looking at this documentation here.

Using that I am getting a lot of error using it. I am not sure if I am using the iab correctly in my html.

Can you explain it with a button click example?

My .ts file

import { Component } from ‘@angular/core’;

import { NavController } from ‘ionic-angular’;

import { InAppBrowser } from ‘@ionic-native/in-app-browser’;

constructor(private iab: InAppBrowser) { }

@Component({
selector: ‘page-home’,
templateUrl: ‘home.html’
})
export class HomePage {

constructor(public navCtrl: NavController) {

}

OpenUrl()
{
const browser = this.iab.create(‘https://ionic.io’);
browser.show()
}

}

.html

    <button class="button" ion-button block (click)='OpenUrl();'>
    CLICK
    </button>

What am I doing wrong. Newbie, so please don’t mind if it’s silly!

3 Likes

Good evening, express yourself well. What do you get as a mistake?

Hi,

With the same code, I have this error :

Runtime Error
Error in ./MyApp class MyApp - caused by: No provider for InAppBrowser!

The solution :

Add : providers: [InAppBrowser]

I can’t open an url using an external browser like safari, on iOS. Ionic 3

I think the constructor is wrong you should have something like this:

constructor(public navCtrl: NavController, private iab: InAppBrowser) { }

to add module first do:

ionic cordova plugin add cordova-plugin-inappbrowser
npm install --save @ionic-native/in-app-browser

then follow above or see

try this:

window.open("http://google.com",'_system', 'location=yes');
21 Likes

it worked for me. tanx

1 Like

This is the best answer i was looking for

2 Likes

Simple and elegant, thanks!

1 Like

This does not work on iOS.

1 Like

Did you resolve it with iOS?

You will also have to install the InAppBrowser plugin. Only installing this plugin it work :slight_smile:

Is there any way to open a local HTML file (ex: asset>test>test.html) by window.open in ionic?

My solution

document.onclick =  (e) => {
        try{
          let event = e || window.event;
          let element: any = event.target || event.srcElement;
          if(element.tagName !== 'A')
            element = element.parentNode;
          if(element.tagName == 'A' && element.href !== undefined){
            if (this._isApp){
                this.iab.create(element.href, "_system", "location=yes,enableviewportscale=yes");
            }else{
                window.open(element.href, "_system", "location=yes");
            }
            return false;
          }
        }catch(e){

        }
      };

just remove the <allow-navigation from the config.xml