How to

30 views
Skip to first unread message

Pritam Mandal

unread,
Jul 2, 2014, 6:23:06 AM7/2/14
to google-ajax...@googlegroups.com
<script async type="text/javascript">
jQuery(document).ready(function () {
jQuery('a[href*="http://"]:not([href*="http://www.cyberindia.in/"])').attr("target", "_blank");
    });
</script>


I am using the above code but it's heavy and on gtmetrix  ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js showing that it's not parsed.

I want to use http://minifiedjs.com/download/minified.js which is light weight and parsed but can't frame the below code to work.


<script async type="text/javascript">
jQuery(document).ready(function () {
jQuery('a[href*="http://"]:not([href*="http://www.cyberindia.in/"])').attr("target", "_blank");
    });
</script>

Basically I want when a out-going link (external link) is clicked on the website it will open in a new window. Please help.

Thanks in advance :)

Jeremy Geerdes

unread,
Jul 2, 2014, 5:26:53 PM7/2/14
to google-ajax...@googlegroups.com
If this is all that you're using jQuery for, I would suggest avoiding any library at all. Just do a simple onload listener or, if you really don't want to wait for that, put the code block at the very end of the body element, right before the closing </body> tag. For what you're trying to do, the DOM will be available at that point. Then, you can call this code, which is entirely DOM-based.

function outsideLinksToNewTab(){
  var els = document.getElementsByTagName('a'),
  rea = /^http:\/\//i,
  reb = /^http:\/\/www.cyberindia.in\//i;
  for(var i=0; els && i<els.length; i++){
    var el = els[i],
    href = el.getAttribute('href');
    if(href.match(rea) && !href.match(reb)){
      el.setAttribute('target', '_blank');
    }
  }
}

jg





--
--
You received this message because you are subscribed to the Google
Groups "Google AJAX APIs" group.
To post to this group, send email to
google-ajax...@googlegroups.com
To unsubscribe from this group, send email to
google-ajax-searc...@googlegroups.com
To view this message on the web, visit
https://groups.google.com/d/msgid/google-ajax-search-api/4465bb15-60f3-4df6-b7e9-9a78eb4076f8%40googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en?hl=en

---
You received this message because you are subscribed to the Google Groups "Google AJAX APIs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-ajax-searc...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jeremy R. Geerdes
Generally Cool Guy
Des Moines, IA

If you're in the Des Moines, IA, area, check out Debra Heights Wesleyan Church!
Reply all
Reply to author
Forward
0 new messages