Parsing URLs with Javascript

So this is pretty cool:

var a = document.createElement('a');
a.href = 'http://louis:[email protected]:1991/cool-app/?callback=parseRep#hash';

a.protocol; // => 'http:'
a.username; // => 'louis'
a.password; // => 'passwd'
a.hostname; // => 'lpil.uk'
a.port;     // => '1991'
a.host;     // => 'lpil.uk:1991'
a.pathname; // => '/cool-app/'
a.search;   // => '?callback=parseRep'
a.hash;     // => '#hash'

The only gotcha seems to be that IE drops the preceding / from pathname.

Thanks hasenj and jlong! :)