Last active
September 4, 2018 11:57
-
-
Save arjunkomath/84e5ea0722f167f216949ee84f241782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('test', ['ngSanitize']) | |
.filter('addTargetBlank', function(){ | |
return function(x) { | |
var tree = angular.element('<div>'+x+'</div>'); | |
for(var i=0;i < tree.find('a').length;i++){ | |
if (tree.find('a')[i].href.indexOf(window.location.hostname) == -1) { | |
tree.find('a')[i].setAttribute('target', '_blank'); | |
} | |
} | |
return angular.element('<div>').append(tree).html(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment