I don’t want the in app browser to open, I want it to open in safari/chrome
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/
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!
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');
it worked for me. tanx
This is the best answer i was looking for
Simple and elegant, thanks!
This does not work on iOS.
Did you resolve it with iOS?
You will also have to install the InAppBrowser plugin. Only installing this plugin it work
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
It’s works!, Thanks!
Hi, this answer may come bit late but the question is still valid and this may help someone that is looking the answer for this issue. I spent hours to get this done. It seems that the only way is to use Cordova’s Inappbrowser.
First, install Cordova InAppBrowser:
cordova plugin add cordova-plugin-inappbrowser
Then replace the window.open
(this step is not necessary, but it makes things simplier)
window.open = cordova.InAppBrowser.open;
Then you can call:
<a href="https://google.com" onclick="window.open('https://google.com', '_system'); return false;">Google</a>
This will open Google in device’s browser. The return false;
is important, otherwise the target URL will be opened in webview as well.
I have written more detailed blog article about the issue here