Just came across this clever solution yesterday, actually. Unfortunately, it doesn't work for URLs containing a username and password (e.g. http://username:password@example.com). Glad to have found URI.js, though--it's exactly what I was looking for.