The Lazy Man's URL Parsing
joezimjs.com
joezimjs.com
It can be corrected by doing:
parser.pathname = parser.pathname.replace(/(^\/?)/,"/");
Further, because you're creating a DOM element, it's less performant than using a RegExp solution. That performance degradation will typically only surface if you're parsing a large number of URLs (for example, in a loop), rather than just 1 or 2.Here are the canonical docs: http://dev.w3.org/html5/spec-LC/urls.html#interfaces-for-url...
And here's a prettier (but less detailed) version: http://developers.whatwg.org/urls.html#interfaces-for-url-ma...
A stylistic point is I'd just call it something like "link". Assigning a link element to "parser" is being cute and it's not what the object actually is, even if it's being used with intent to parse.
Takes you here: This webpage has a redirect loop The webpage at http://www.joezimjs.com/500.shtml/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer. Here are some suggestions: Reload this webpage later. Learn more about this problem. Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
Instead of here: http://www.joezimjs.com/javascript/the-lazy-mans-url-parsing...
I'm not sure why it produced an redirect loop because it worked many times for a lot of people. It may have had something to do with my server getting overloaded. I'm on a Hostgator reseller account, so I have limited resources and when HG saw the massive CPU usage from all of you people checking this out, they shut down my site for a bit.
The way I see it, about half of my salary is for caring about IE7. IE7 hacks and stupidities occupy no more than 5-10% of my time, but the way I see it, 80% of my work is damn fun and I would do it for free. I am glad that there is the remaining 20% of IE7 hacking, boss-assigned-task-doing, and so on for which I (consider myself to) get paid 5x my actual salary.