[wp-hackers] XHTML Strict compliant replacement for target=_new

Amit Gupta wp at igeek.info
Sat Oct 22 14:22:24 GMT 2005


Jason Bainbridge <jbainbridge at gmail.com> wrote:
|  Firstly I think the whole target=_new thing is a pain to begin with,
|  if I want to open a link in a new window I'll middle click on it 
thank
|  you very much and if the damned link uses Javascript and the middle
|  click fails then more often then not I just won't follow the link.

have you tried the code Jason? I suggest you try it first before 
commenting
on it. Middle-click & right-click "new window" work just like they 
should work.
its just that the target attribute is added via DOM which is not seen by 
any
validators.

|  For this reason along with not wanting Javascript to be a requirement
|  just for a visitor to click a link then I don't think this is a good
|  solution so my vote goes for either scrapping the target=_new all
|  together or if it must stay then implementing the alternative
|  rel="external" solution posted in a later post.

again, Javascript is not a requirement for those links. They are 
perfectly alright
links which will open in the same window if the javascript is disabled 
or the
javascript file is not included in it the page. what that javascript 
does is just
get all the <a> tags which have an "href" attribute & a "rel" attribute 
whose
value is "external" and adds the 'target="_blank"' attribute to them, 
that's all!!

and if you don't know, that article was written by Kevin Yank who is a
respected author in the web-dev field & he doesn't write trash!! also, I 
think
that Simon Willison wrote a javascript function like that as well, 
though
I can't find a link.

also, if you still find it a problem to use that function, you can use 
the following one instead!!

~~~~~~~~~
function externalLinks() {
    if(!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for(var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if(anchor.getAttribute("href") && anchor.getAttribute("rel") == 
"external") {
            anchor.onclick = 
function(){window.open(anchor.getAttribute("href"));return false;};
        }
    }
}
window.onload = externalLinks;
~~~~~~~~~

------------
Amit Gupta
http://igeek.info/  ||  http://blog.igeek.info/
http://blog.igeek.info/wp-plugins/igsyntax-hiliter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://comox.textdrive.com/pipermail/wp-hackers/attachments/20051022/6a36ecec/attachment.htm


More information about the wp-hackers mailing list