Links not opening in system browser?

I’m trying to open links in the device’s system browser but it isn’t working. I’m getting my data/links from a json file on a http.get request.

The code i’m using is from here http://intown.biz/2014/03/30/cordova-ionic-links-in-browser/

My code:

HTML:

 <p style="text-align:left"> <span ng-bind-html="item.content | externalLinks"></span></p>

Javascript:

Filter:

.filter('externalLinks', function() {
   return function(text) {
     return String(text).replace(/href=/gm, "class=\"ex-link\" href=");
   }
 });

Js:

    .controller('announcementCtrl', function($scope, $http, $ionicLoading, $ionicPopup, $timeout) {
    
       $timeout(function () {
       $('.ex-link').click(function () {
         var url = $(this).attr('href');
         window.open(encodeURI(url), '_system', 'location=yes');
         return false;
       })
    })
  });

I’m not receiving any errors it just isn’t working. I

In your config.xml, do you have the following?

<access origin="http:*" launch-external="yes"/>
<access origin="https:*" launch-external="yes"/>

If not, try adding it. This is happening because all external links by default are blocked.

1 Like

I added that but it still isn’t loading links in the systems browser. Any more ideas?

What happens if you alert the url variable before the window.open?

1 Like

What do you mean? Just add an alert box?

I added two alertboxes to my code. For some reason they load when the application starts?

I’m with the same problem. I have been trying in every way but unfortunately without success. The site replaces my app and I don’t have a way to back to my app.

I found a solution but after a while it crashes my application: https://github.com/Shoety/cordova-plugin-inappbrowserxwalk.

ps: I use crosswalk.

Finally I found a solution:

<a ng-click="openURL("https://www.google.com.br")"/>

$scope.openURL = function (url) {
    navigator.app.loadUrl(url, { openExternal:true });
}

This worked for me.

My links are being inputted from a Http.get Json file so i can’t do it like that.

What if you did this beefman?

<a ng-click="openURL("json.url")"/>

If this doesn’t work try:

<a ng-click="openURL(json.url)"/>

Might work, i’ll give it a go.