Rectangle 27 0

jQuery External Link Snippet for XHTML Strict 1.0

There are plenty of jQuery snippets like this on Snipplr, but most of them are either overly complicated or defeat the object of not using the target attribute in your HTML. (Although to be honest, if you're 100% XHTML Strict and even vaguely Web Standards-minded you should let the user decide whether or not to open a link in a new window - we shouldn't force it upon them ).

This one however, IS simple - it looks for all anchor tags with rel="external" (the correct way to specify an external link) and binds a click event to them which, when activated, prevents the default action and opens the link in a new window.

Not a target attribute in site!

jQuery
Rectangle 27 0

jQuery Targets for External Links in XHTML 1.0 Strict

XHTML 1.0 Strict does not allow the target attribute on links. The recommended way of specifying external links is to give the link a rel attribute of "external". This jQuery snippet finds likes with rel attributes of "external" and dynamically adds a target attribute of "_blank" so they will open in a new tab/window while maintaining valid XHTML 1.0 Strict code.

jQuery