Previous Message
Next Message

if you can not target with xhtml strict

Sent by Brian Cummiskey on 5 April 2005 16:04


> Little Girl wrote:
> 
>> If you can not targer="_blank" with xhtml strict, how are you supposed to
>> achieve the same result?

Christain Heilmann wrote this a couple days back:
------------------------------------------------
You cannot replace functional attributes like target with CSS. You need 
a script to do the job for you.

Personally I am using this one:
function externallinks()
{
    var c=document.getElementById('content');
    if(c)
    {
        var ls=c.getElementsByTagName('a');
        for(var i=0;i<ls.length;i++){
            if(ls[i].getAttribute('rel')=='external')
            {
                ls[i].className+=ls[i].className?' extlink':'extlink';
                ls[i].title+='(opens in new window)';
                ls[i].onclick=function(){window.open(this.href);return 
false}
            }
        }
    }
}
which  gets called when the page is loaded.
window.onload=function(){
    if(!document.getElementById && !document.createTextNode){return;}
    externallinks();
}

It opens every link inside the element with the id content that has the 
attribute rel="external" in a new window (circumventing the illegal 
"target") and adds the class "extlink" to these links. Furthermore it 
adds a title that tells the user that this link will open in a new window.

HTH
Chris

______________________________________________________________________
css-discuss [EMAIL-REMOVED]]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
Previous Message
Next Message

Message thread: