Opening href from code embed in an Ionic app


I’m facing a little problem, on my app I’m receiving code embed, like :

<a href="">Link to Google</a>

So this little piece of HTML will be well rendered in app. But if the user want to click on the link, this will open a window that create an overlay over the app with the web site. And it’s impossible to go back, the user need to close the app. This code embed can be very different, so a ‘fixed’ solution cannot be used.

Another solution is to parse the code embed, if <a href> is found, add inside the <a href> a (tap) action.
Like <a href="" (tap)="openExternally('')>Link to Google</a>". And the openExternally() function should be :
(using inAppBrowser plugin)

openExternally(url) {

But I think this is a big operation, because some code embed can be huge… If there is others solutions, thanks in advance.

After some tests, I have this :

  parsingHtml(html) {
    let el = document.createElement('div');
    let codeEmbed;

    el.innerHTML = html;
    codeEmbed = el.getElementsByTagName('a');
    if (codeEmbed.length) {
      for (let anchor of codeEmbed) {
        anchor.setAttribute('on-tap', 'toAFunction()');
    this.newsContent = el.outerHTML;

  toAFunction() {

On the DOM I see the on-tap on the href, but the toAFunction() is never working…
And the is link always opened in app.

Finally I added this code to the index.html :

    document.onclick = function (e) {
      e = e || window.event;
      var element = || e.srcElement;

      if (element.tagName == 'A') {
, '_blank', 'location=yes', 'zoom=no');
          return false;

      if ((element.tagName == 'STRONG' || element.tagName == 'I') && e.srcElement.parentElement.href) {, '_blank', 'location=yes', 'zoom=no');
        return false;