PDA

View Full Version : XHTML and a tag target attribute


kehers
09-08-2006, 01:02 PM
seems xhtml 1.0 strict version doesnt support the target attribute for a tags. Any workaround for this? thinking of using a javascript event to target d link to d one I want onclick but was just wondering if there is a better way.

Bill Posters
09-08-2006, 01:19 PM
It's increasingly being accepted that new windows are a behavioural/functional effect and, as such, belong in the realm of scripting.
Imho, using js is the appropriate way to implement new windows.

Create the link as a standard, targetless anchor and then overlay some js to divert it to a new window.
Done properly, the link remains usable to both js and non-js users, but js users get your 'optimised' version with the new window.

(Be sure to fully consider whether the new window is really necessary or helpful to the author or, more importantly, the user. Be sure that you aren't using a new window simply because it's technically possible.

If you aren't sure, tell us what you intend to use the new window for and perhaps we can help you find out whether or not a new window is the best all-round solution.)

kehers
09-08-2006, 01:40 PM
Added 'Search d web with Google' snippet which has to load d result on a seperate page. A part of the site also allows for miscellanous articles from which i would prefer included links in the article to be loaded in another page than covering the main one.

Tails
11-20-2006, 03:42 AM
While the target attribute is now gone, is it confirmed that window.open is still a valid solution? I'm not sure if the removal of target was intended to remove popups from the specification, or to separate markup from client-side scripting.

What also raises my confusion is that nearly every (if not all) semi-colon separated 'option' fed to window.open is proprietary, branching between IE4 and some version of Netscape. Has window.open been proprietary all along? There's really no standard body like w3C providing documentation and validation for javascript, is there?

Bill Posters
11-20-2006, 08:47 AM
While the target attribute is now gone, is it confirmed that window.open is still a valid solution? I'm not sure if the removal of target was intended to remove popups from the specification, or to separate markup from client-side scripting.
window.open certainly is still a 'valid' solution.

The reasons behind the deprecation of the target attribute are two-fold.
To reduce markup language down to a more portable set of elements and attributes, making markup language more platform-independent.
To cleanse the markup language of elements and attributes which aren't strictly structural or semantic.

The issue with the target attribute was that only more complex UAs such as common desktop browsers (e.g. FF, IE, Opera, Safari, etc…) could facilitate the creation of multiple windows.
Additionally, the creation of new windows is seen as a 'behaviour' and not something which belongs in a markup language focussed on structure and semantics.

The layer which should be used to implement behavioural effects is scripting, the most common and widely supported of which is javascript.

What also raises my confusion is that nearly every (if not all) semi-colon separated 'option' fed to window.open is proprietary, branching between IE4 and some version of Netscape. Has window.open been proprietary all along? There's really no standard body like w3C providing documentation and validation for javascript, is there?
ECMA (http://www.ecma-international.org/publications/standards/Ecma-262.htm)
The W3C also have a Document Object Model (DOM) recommendation which is a node-based representation of a document, which can be tapped into and manipulated using DOM-oriented javascript methods (e.g. document.getElementById(), …).

Afaik, there is no 'validator' facility for js in the sense that you can run a document which uses js or a js file through it and have errors listed.
However, numerous modern browsers have a js error alert facility built in which can be used to report any js errors at runtime (when the script itself is actually being run).

Firefox has a number of extensions built to enhance and improve these reports, the best of which is Firebug (https://addons.mozilla.org/firefox/1843/).

rpgfan3233
11-20-2006, 09:13 AM
Just for those that are interested, the current XHTML 2.0 Working Draft (http://www.w3.org/TR/2006/WD-xhtml2-20060726/) has the target attribute defined for XHTML 2.0 (http://www.w3.org/TR/2006/WD-xhtml2-20060726/mod-hyperAttributes.html#adef_hyperAttributes_target).

VIPStephan
11-20-2006, 11:31 AM
I'm using the method explained on sitepoint.com (http://www.sitepoint.com/article/standards-compliant-world) for opening new windows (target="_blank" replacement).

Bill Posters
11-20-2006, 11:59 AM
I'm using the method explained on sitepoint.com (http://www.sitepoint.com/article/standards-compliant-world) for opening new windows (target="_blank" replacement).

Fwiw, that formed the basis of a method which I built for myself a while back. I felt that the Sitepoint script was simply too basic in that it lacked certain accessibility and usability aids.

The method at 465BereaStreet site (which I think may have been partly influenced by my own script) takes many of these things into consideration...
http://www.456bereastreet.com/archive/200610/opening_new_windows_with_javascript_version_12/

kehers
11-24-2006, 04:19 PM
Its kinda freaky i know, but my workaround goes this way:

<a href="page.htm" onclick="this.target='_blank'">link</a>

;)

Bill Posters
11-24-2006, 04:57 PM
Its kinda freaky i know, but my workaround goes this way:

<a href="page.htm" onclick="this.target='_blank'">link</a>

;)
That's a very long-winded way if you have multiple anchors to effect.
+
It's increasingly considered best practice to avoid using inline events/scripting.