Skip to content

Instantly share code, notes, and snippets.

@arjunkomath
Last active September 4, 2018 11:57
Show Gist options
  • Save arjunkomath/84e5ea0722f167f216949ee84f241782 to your computer and use it in GitHub Desktop.
Save arjunkomath/84e5ea0722f167f216949ee84f241782 to your computer and use it in GitHub Desktop.
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