How to create a hyperlink that can be opened in both iOS and Android?

Hi,

I used standard HTML a tag. It works in iOS, but gives error in Android and app crashes)

Error in Android

Application Error
net::ERR_FILE_NOT_FOUND (file:///android_asset/www/www.youtube.com/embed/kEU9q1LOcI0)

Code1:

<p class="greenText">How it works? <a href="www.youtube.com/embed/kEU9q1LOcI0">Watch a 2min intro video!</a></p>

Code2:
I try use this googled solution, not working either

        <p class="greenText">How it works?
          <a class="item" href="#" onclick="window.open('www.youtube.com/embed/kEU9q1LOcI0', '_self', 'location=yes'); return false;"> Watch a 2min intro video!</a>
        </p>

Any help?

1 Like

Install the inapp-browser plugin.

Then something like…

<button ion-button (click)="openUrl()">Open Url</button>

And in your code…

openUrl(){ window.open('https://www.youtube.com/embed/kEU9q1LOcI0', '_system'); }
2 Likes

And the inline problem you have with the file not found this is coz you’ve not included http:// or https:// at the beginning.

Thanks! This really cleared my puzzle!

One more question, what is the benefit of using the inApp browser plugin? So the user doesn’t need to jump to another browser to view additional info?

In my case, opening youtube by youtbue app or browser is better than from inApp browser

It can still open via the regular browser, YouTube is perhaps a special case.

The in app browser gives you a nice separation from your actual app eliminating CORS type issues and the user isn’t lifted out of your app.

Look it up. I’m doing it a disservice.

thanks for the explanation! I will give it a try.