Open external links in new window by default

Argos

Hi Maverick, that's a cool alternative, thanks!
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!

maverik

#2
this what you do will jquery do with the filter function. and with an extra css class you can put some nice icons to the link.

if  jquery is loadet in the head then use

$("a").filter(function() {
   return this.hostname && this.hostname !== location.hostname;
}).addClass('external').attr("target", "_blank");


and css

a.external {
   background: url(/path/to/your image/external.png) center right no-repeat;
   padding-right: 13px;
}


so no other script then jquery is nessesary.

it works on www.WebsiteBaker.net

sorry for my bad english , i hope you understand what i mean

greets


[gelöscht durch Administrator]

Argos

In all my sites I use a little javascript that automatically makes sure that all links to other domains open in a new window. it overrides local link settings, so setting target="_blank" etc is not required anymore. It's a very handy script, and I think it would be nice to add it to the core settings of WB if possible, or make it into something that other uses can easliy add to their installation. I'm not sure about the best way. This is the call you need to add to the HEAD of your template:
<script language="JavaScript1.2" type="text/JavaScript" src="<?php echo TEMPLATE_DIR?>/linkstarget.js"></script>

Of course the path can be different, the script can be placed anywhere, as long as you point to it.

The script itself is:
//1)Enter domains to be EXCLUDED from opening in new window:
var excludedomains=["yourdomain.com", "www.yourdomain.com"]

//2)Automatically open offsite links in new window? (1=yes, 0 will render a checkbox for manual selection)
var auto=1

var excludedomains=excludedomains.join("|")
rexcludedomains=new RegExp(excludedomains, "i")

if (!auto)
document.write('<form name="targetmain"><input type="checkbox" name="targetnew" checked onClick="dynamiclink()">Open off-site links in new window</form>')

function dynamiclink(){

if (auto||(!auto&&document.targetmain.targetnew.checked)){
for (i=0; i<=(document.links.length-1); i++) {
if (document.links[i].hostname.search(rexcludedomains)==-1&&document.links[i].href.indexOf("http:")!=-1)
document.links[i].target="_blank"
}
}
else
for (i=0; i<=(document.links.length-1); i++) {
if (document.links[i].hostname.indexOf(mydomain)==-1)
document.links[i].target=""
}
}

if (auto)
window.onload=dynamiclink


Where "yourdomain.com" in the top of the script should be replaced by the domain you use. Maybe a WB coder can rework it into something more WB'ish, or give tips on how to do that myself? I'm not a coder, and my php and javascript skills are limited.
Jurgen Nijhuis
Argos Media
Heiloo, The Netherlands
----------------------------------------------------------------
Please don't request personal support, use the forums!