Hi,
So here's a mini tip:
How to Make all links that leads out of your site open in a new tab.
That means , links that doesn't contain your network domain , will be opened in a new tab. This method can be used so that your network doesn't lose precious traffic because of external links.
Normally if we do it using HTML , we will just add a target="_blank" attribute to it. What if user put an external in a comment , we can't edit the content.
<a href="externallink" target="_blank">External Site</a>
This is when the awesome jQuery steps in, just copy this code into your custom code:
<script type="text/javascript">
if (typeof(x$) != 'undefined') {
//look at each links on your network
//if link has http
x$("a[href^=http]").each(function(){
//if the link does not contain your hostname (yournetwork.com)
if(this.href.indexOf(location.hostname) == -1) {
//add attribute target to it to open in new tab
x$(this).attr('target','_blank');
}
}); //end of each function
}
else{
}
</script>
I'm using jQuery's .each() and .attr() to get the work done.
Location.hostname is to get your domain name mynetwork.com
.indexOf is use to see if a string contains something.
== -1 That means does not exist!
That's it. Hope you like it.
Tags:
Permalink Reply by Jordon McGee (Jords) on October 10, 2012 at 8:51am Great tip!
Permalink Reply by Alexander Korf on October 10, 2012 at 9:14am thanks, great script!
Permalink Reply by Armani Rouse on October 10, 2012 at 11:24am excellent tip Elson, right on brotha!
Permalink Reply by Scott Bishop on October 10, 2012 at 11:25am This is an important mini tip. Question, I have 2 websites meshed as 1 (Ning with a .php site).
How would you write it so both sites stay on target?
Try this , replace otherdomain.com/file.php with your other site link:
<script type="text/javascript">
if (typeof(x$) != 'undefined') {
//look at each links on your network
//if link has http
x$("a[href^=http]").each(function(){
//if the link does not contain your hostname (yournetwork.com)
if(this.href.indexOf(location.hostname) == -1 || this.href.indexOf('otherdomain.com/file.php') == -1) {
//add attribute target to it to open in new tab
x$(this).attr('target','_blank');
}
}); //end of each function
}
else{
}
</script>
Permalink Reply by George H. Compton IV on October 10, 2012 at 1:35pm This is a great tip thank you Elson :)
Permalink Reply by Manuel France on October 10, 2012 at 9:02pm MINI??? MAXI!!! Thank you VERY much Elson
glad you all like it.
Permalink Reply by Tyler Durbin on October 11, 2012 at 3:14pm That worked AWESOME Elson! Thanks!!!
Permalink Reply by Abel I. Arenivar on October 11, 2012 at 4:14pm Gracias me funciono de maravilla.

i covered this back in 2011 here but i like your solution much better!
Cindy replied to Allison Leahy's discussion 'What is your Ning 3.0 URL?' in the group The Sandbox
Kos replied to Allison Leahy's discussion 'What is your Ning 3.0 URL?' in the group The Sandbox
Kos replied to Allison Leahy's discussion 'What is your Ning 3.0 URL?' in the group The Sandbox
Kos replied to Allison Leahy's discussion 'What is your Ning 3.0 URL?' in the group The Sandbox
Kos replied to Allison Leahy's discussion 'What is your Ning 3.0 URL?' in the group The Sandbox
Kos replied to Donna Mac's discussion '3.0 Video - can someone explain?'
Crestini Activi ! replied to Rafael's discussion 'Multiple Chat rooms for Ning 3.0'© 2013 Created by Ning.
