Function ExternalLinks with array of domains


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /* ------------------------------------------------------------------
  2.   External Link ---------------------------------------------------- */
  3. $.fn.externalLinks = function(arrDomains) {
  4. return this.each( function() {
  5. $("a", this)
  6. .filter(function(){
  7. for ( var i=0; i < arrDomains.length; i++ ){
  8. if(this.href.indexOf(arrDomains[i])>-1 ) { return false; }else{ return true; }
  9. }
  10. })
  11. .attr({ target:"_blank", rel:"external" });
  12. });
  13. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.