XHTML Strict target resolved with jQuery

All good web developers now design sites using the XHTML Strict DTD. Strict XHTML forbids the use of the target="_blank" attribute on anchors, used to open a link in anew browser window. The reason for this is that there should be a separation between presentation and behaviour.

This is all fine and dandy until your customer requests that all links to external sites open in a new browser window. This is not an unreasonable request.

The answer is to add an an event to such links using Javascript. As a fan of jQuery, this could not be easier.

Step 1. Add a rel attribute to all external links/anchors

e.g. href="externalsite.com" rel="external"

Step 2. Include the following jQuery script

$('a[rel=external]‘).attr(’target’, ‘_blank’);

If adding the target attribute seems like a hack, then the following should achieve the same goal

$('a[rel=external]‘).click(function(){window.open(this.href); return false});

This may all seem a bit obvious, but I’m sure there’s someone out there looking for an elegant fix like this.

Yahoo Pipes and JQuery : Goodbye Same Origin Policy

I was chatting yesterday with my friend Simon about my somewhat late discovery of Yahoo! Pipes. I knew about it, I’d just never played with it. Pipes is ideal if you’re looking to create a mash-up from RSS feeds. Simon asked if Pipes were constrained by the Same Origin Policy whereby XHR requests are restricted to the domain serving the original page. I said I’d look into it.
more »

Categories

Archives

November 2008
M T W T F S S
« Oct    
 12
3456789
10111213141516
17181920212223
24252627282930

Diversions