0

Following this great answer

I'm using cordova 2.0.

I need to open in safari window some specific links. But at the same time I need to load external ads in the same WebView. So I'm using this conf:

OpenAllWhitelistURLsInWebView = YES
ExternalHosts = ['*']

Setting that I'm not having any problems with ads/GA/et. However, for links I've tried using target=_blank as many posts said but setting ExternalHosts = ['*'] seems to break the target=_blank functionality.

example

<a href='external.com' target=_blank> open in Safari</a>
<a href='internal.com' > open in WebView</a>

Question:

It is possible to force a link target to be opended into safari window using ExternalHosts = ['*'] and OpenAllWhitelistURLsInWebView = YES ??

Community
  • 1
  • 1
Martin Borthiry
  • 5,256
  • 10
  • 42
  • 59

2 Answers2

0

This looks like it might work. I'm running 2.1 an running into the same problem.

I'm still looking for a more eligent solution. http://www.rigelgroupllc.com/blog/2012/05/22/opening-links-in-phonegap-apps-in-mobile-safari/

CertDoctor
  • 101
  • 1
  • 7
0

Just catch all links in your javascript that have target="_blank", and pass them to window.open with the '_system' param. This will work on both iOS and Android.

$(document).on('click', 'a[target="_blank"]', function(ev) {
  var url;

  ev.preventDefault();
  url = $(this).attr('href');
  window.open(url, '_system');
});
Ryan
  • 5,416
  • 1
  • 39
  • 36