Open external content with A[target='_blank'] for web browser but InAppBrowser for mobile device


#1

Hello,

I am using Ionic with the same code for a mobile device and a single-page web app. I’d like to open external content using target="_blank" in the browser to avoid javascript pop-up issues, but use $cordovaInAppBrowser plugin on mobile devices.

Are there any bad side-effects to using this code? Or is there a better way to do this?

<a ng-href="{{anchorClick(url)}}" 
   ng-click="anchorClick(url,$event)"
   target="_blank"> 
   [markup]
</a>
anchorClick: (url,ev)->
    return if !url

    # use HTML target="_blank" for browsers
    return url if ionic.Platform.isWebView()==false

    # $cordovaInAppBrowser.open for devices
    return 'javacript:void(0)' if !ev
    ev.stopImmediatePropagation()
    options = {
      location: 'yes'
      clearcache: 'yes'
      toolbar: 'no'
    }
    $cordovaInAppBrowser.open(url, '_system', options)
    return false

see: http://stackoverflow.com/questions/38289824/open-external-content-with-a-target-blank-for-web-browser-but-inappbrowser-fo