Open external links in new window without target = _blank using jQuery


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



Copy this code and paste it in your HTML
  1. $(document).ready(function() {
  2. externalLink();
  3. });
  4.  
  5. function externalLink() {
  6. $("a[@href^=http]").each(
  7. function(){
  8. if(this.href.indexOf(location.hostname) == -1) {
  9. $(this).attr('target', '_blank');
  10. }
  11. }
  12. )
  13. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.