0

I have an Ionic 1 app which includes Google Maps via the ngMap directive. This works great.

What doesn't work great is when the user clicks on the "Credits" element in the map and the entire app is redirected away to the Google map credits page- and because it's an Ionic app, there is no way for the user to go back.

Is there a way in Ionic / Angular (not jQuery) to intercept arbitrary links like these so that they open in an in-app or system browser?

isherwood
  • 58,414
  • 16
  • 114
  • 157
caitlin
  • 2,769
  • 4
  • 29
  • 65

1 Answers1

0

Usually it is done as follows:

http://codepen.io/anon/pen/MpgrdN

function isExternal(href) {
  return true;
}
document.body.addEventListener('click', function(e) {
  var maybeA = $(e.target).closest('a');
  if (maybeA.length && isExternal(maybeA[0].getAttribute('href'))) {
      // window.open()
      console.log('prevented');
      e.preventDefault();
  }
});

Used jQuery closest function, if no jQuery on page standalone implementation is here DOM / pure JavaScript solution to jQuery.closest() implementation?

Community
  • 1
  • 1
Andrii Muzalevskyi
  • 3,261
  • 16
  • 20