Standards Compliant External Links

By on

I don’t like opening links in new windows for lotsofreasons. But it seems to be a necessary evil at times (e.g. boss or client makes you). One of the better arguments I’ve heard made, is when a user is browsing a sensitive, secured website (such as a banking website). If she clicks on a link to an external resource she may forget that she is still logged in to the sensitive website and thus forget to log out. The problem comes in that opening a link externally is not part of the HTML 4.01 or XHTML 1.0 Strict DTDs. So we have to rely on alternative methods (namely Javascript) to do it for us in a standards compliant manner. I really like the method found on Andrew Porter Glendinnings old blog:

The JavaScript on this page gets around this problem in a standards-friendly manner. An onload event handler is attached to the document that goes through all the links looking for a class value of “external” and attaches an onclick handler to each link it finds with one. That handler opens a new window using the link’s href value. > Standards-based Replacement for in External Links> . 5 Apr 2006. [Online] > Andrew Porter Glendinnings old blog> .