target="_blank", but thanks to Javascript and the DOM(Document Object Model), now you can. Kevin Yank writes about this method in his article "Window Links in a Standard Compliant World".
The HTML(HyperText Markup Language) 4.0 specification took away theSo, in a nutshell, by usingtargetattribute, but it added another attribute:rel. This attribute is intended to specify the relationship between the document that contains the link, and the target of the link. The specification defines a bunch of standard values for this attribute (e.g.next,previous,chapter,section), most of which have to do with relationships between small sections of a larger document. However, the spec leaves the developer free to use nonstandard values for site-specific purposes.
<a href="document.html" rel="external">external link</a>, and some DOM(Document Object Model) logic, you can change all of the links you want in a compliant manner.
Very, very slick stuff. ( via "What Do I Know(Todd Dominey)":http://whatdoiknow.org/ )
Tagged As Coding, HTML, Javascript
Comments are Open (8)
Posted at 04:53 PM
Comments
sysifus
I think that after applying that method, the document becomes invalid. In any case the attribute is incorrect.
IMHO it is easier to write: <a href="foo.html" onclick="window.open(this.href);">
Posted by: sysifus | May 6, 2003 01:16 PM
Tony
Actually, the document doesn't become invalid, because when it validates, it validates the code pre-javascript. The Javascript code is on the client side, not server side. And the Javascript uses the DOM, which is a separate standard that XHTML.
I tend to agree with your solution for the time being. But once I use this new method for a while, I'll probably find it easier. It's just what you're used to.
Posted by: Tony | May 6, 2003 01:26 PM
sysifus
Well, I think that document must be valid in any moment, not only before the script execution or when you validate it. DOM changes the structure of the document, and the validator always runs without the script.
Posted by: sysifus | May 6, 2003 04:41 PM
Tony
But the DOM is a separate schema. It's governed by a different set of validation rules. The Document Object Model (DOM), which governs the document objects and attributes that are available to JavaScript code, is a totally separate standard from (X)HTML. Also consider that the DOM 2.0 standard that was published in January 2003 (well after XHTML 1.0, let alone HTML 4.0) still includes this attribute. It seems clear that while this attribute is slated to be phased out of (X)HTML, it will be available to JavaScript through the DOM for the foreseeable future.
Posted by: Tony | May 6, 2003 06:39 PM
sysifus
I think DOM is not totally separate from (X)HTML. From the DOM level 1 introduction:
"... The semantics of those languages are defined by W3C Recommendations for these languages (XML or HTML). The DOM is a programming model designed to respect these semantics..."
Whereas DOM level 3 Validation is not still a specification, IMHO the author has the responsibility to maintain the validity.
Posted by: sysifus | May 7, 2003 02:59 AM
Tony
Mmmm.... that's an interesting point.
But what is being done here by the DOM is basically allowing site-wide changes to your site (much like CSS) so that links can open new windows. Since target=_blank isn't allowed, and won't validate, this by-passes that restriction.
Bear with me while I think aloud... Now, if we use your initial option (OnClick=...), and someone has Javascript turned off, the link opens in the same window. Same with the DOM modification. In the future, your suggestion will still hold valid. But it will be on each individual link. More code? Certainly more characters per link. Larger code. DOM modification way: less code. Can update easily in one place to take advantage of browser improvements. Restricts the rel tag to only external, forward, back etc are barred from those links. Could handicap user later.
Interesting. I really don't know. I still think that this modification using Javascript is okay, and valid. I'm not using it here, but I think it's okay. But I am certainly not as sure anymore.
Mmm... I just don't know. You raise some really valid points sysifus.
Posted by: Tony | May 7, 2003 07:02 AM
sysifus
:-) Well, perhaps this conversation is too "puristic".
About the "onclick..." option, if you omit the attribute in the HTML code, but you make a small change in the script, the amount of code is equal: using DOM you can add the onclick attribute instead of adding the target attribute.
Posted by: sysifus | May 7, 2003 08:41 AM
Tony
That sounds like a good solution to the issue at hand. You would still use "Correct" and "Valid" code, pre- and post- Javscript modifications, and still get a target attribute functionality.
Yeah. I think that might be the best way around it.
Posted by: Tony | May 7, 2003 08:47 AM