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
EffakT
July 17, 2015, 1:19am
2
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?
EffakT
July 17, 2015, 1:32am
4
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?
Senkai
July 17, 2015, 11:36pm
7
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.
Senkai
July 18, 2015, 1:35am
8
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.
EffakT
July 20, 2015, 1:32am
10
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.