Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic application open link in system browser

I want to open the link in the system browser, for example in ios in safari and for android chrome(whatever the default browser is).

The problem i'm having the that the link does indeed opens in the system browser but it also open in the application. I want the link only to open in the system browser and not inside the app.

this is my code.

<a ng-href="http://example.com/login/{{user._id}}" onclick="window.open(this.href, '_system', 'location=yes')" class="ion-home color-primary item"> Dashboard</a>

Keep in mind that im also passing an id to my endpoint.

like image 225
Millenial2020 Avatar asked Feb 22 '16 20:02

Millenial2020


People also ask

How do I open the browser in Ionic app?

Using Browser. It is very easy to start working with this plugin. All you need to do is to open the command prompt window and install the Cordova plugin. This step allows us to start using the inAppBrowser.

How do I open external links in Ionic app?

Ionic apps are developed with angular code, so people start using ng-href to point to URLs which has {{}} variables whose value will be dynamically loaded. With ng-href IONIC treats the links like internal links and hence opens them within the application itself.

What is ionic4?

Ionic 4 represents the culmination of more than two years of research and hard work transforming Ionic from “mobile for Angular” into a powerful UI Design System and app framework for every web developer in the world.


4 Answers

try

<a class="ion-home color-primary item" href="#" onclick="window.open('http://example.com/login/{{user._id}}', '_system', 'location=yes'); return false;"> Dashboard</a>
like image 109
Santiago Avatar answered Oct 18 '22 15:10

Santiago


In newer(3.0) version In App Browser Plugin is better solution.

<button ion-button block clear (click)="openWebpage(url)">Open Webpage</button>

and the openWebpage method goes like this

 openWebpage(url: string) {
        const options: InAppBrowserOptions = {
          zoom: 'no'
        }

        // Opening a URL and returning an InAppBrowserObject
        const browser = this.inAppBrowser.create(url, '_self', options);

       // Inject scripts, css and more with browser.X
      }
like image 30
Prashant Avatar answered Oct 18 '22 13:10

Prashant


You can do it with InAppBrowser plugin https://cordova.apache.org/docs/en/3.0.0/cordova/inappbrowser/inappbrowser.html

If you for some reason don't want to use plugin, check out my answer on similar question: https://stackoverflow.com/a/30397786/1630623

EDIT: if you are already using the plugin, you might have to either remove the onclick code and add target="_system", or add event.preventDefault(); in the onclick handler

like image 6
Frane Poljak Avatar answered Oct 18 '22 13:10

Frane Poljak


Capacitor has an easy to use plugin for launching an in-app browser.

https://capacitorjs.com/docs/apis/browser

Installation:

npm install @capacitor/browser
npx cap sync

Usage:

import { Browser } from '@capacitor/browser';

const openCapacitorSite = async () => {
    await Browser.open({ url: 'http://capacitorjs.com/' });
};
like image 4
Tobija Fischer Avatar answered Oct 18 '22 14:10

Tobija Fischer