Revision: 7806
Updated Code
at April 14, 2011 05:05 by wizard04
Updated Code
//for links in XHTML that should open in another window (since the target attribute is invalid)
//to use it, add class names to the links like so: target-windowName, target-_top, or simply target- for "_blank"
//BEWARE! it replaces any function that is already assigned to the onclick event
function setUpTargetLinks()
{
var links = document.getElementsByTagName("a");
var name;
for(a in links)
{
name = a.className.replace(/(?:^|.*\s)target-([a-z0-9_-]*).*$/i, "$1");
if(name == "_self") continue;
if(name == "_blank") name = "";
if(name == "_top")
a.onclick = function(){ window.top.location = a.href; return false; };
else if(name == "_parent")
a.onclick = function(){ window.parent.location = a.href; return false; };
else
a.onclick = function(){ return !window.open(a.href, name); };
}
}
Revision: 7805
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at August 13, 2008 16:11 by wizard04
Initial Code
//for links in XHTML that should open in another window (since the target attribute is invalid)
//to use it, add class names to the links like so: target-windowName, target-_top, or simply target- for "_blank"
//BEWARE! it replaces any function that is already assigned to the onclick event
function setUpTargetLinks()
{
var links = document.getElementsByTagName("a");
var name;
for(a in links)
{
name = a.className.replace(/(?:^|.*\s)target-([a-z0-9_-]*).*$/i, "$1");
if(name == "_self") continue;
if(name == "_blank") name = "";
if(name == "_top")
a.onclick = function(){ window.top.location = a.href; return false; };
else if(name == "_parent")
a.onclick = function(){ window.parent.location = a.href; return false; };
else
a.onclick = function(){ window.open(a.href, name); return false; };
}
}
Initial URL
Initial Description
Initial Title
XHTML Targetted Hyperlinks
Initial Tags
javascript, link, window, xhtml
Initial Language
JavaScript