The same URL can be represented in many different representations.
e.g. Assuming the browser’s currently loaded page ishttp://www.example.com/about.html
The following URLs can be considered equivalent from the browser’s point of view:
http://www.example.com/contact-us.htmlandhttp://www.example.com/contact-us.htmlhttp://www.example.com/contact-us.htmlandcontact-us.htmlhttp://www.example.com/contact-us.htmland.http://www.example.com/contact-us.htmland/contact-us.html
With this in mind, is there an easy way to determine this equivalence using JavaScript?
Or, is there a way of obtaining a canonical form of a URL such that the canonical forms can be compared as a way of reaching the answer?
I’ve noticed that when you read an href from an
<a href="xxx">tag via javascripttagObj.href, you always get a fully qualified URL. So, one possibility for your question is to create a hidden<a href="xxx" style="display: none;">tag, set whatever test URL into it that you want and then read it back. You will get what the browser thinks the fully qualified URL is for that, whether it’s “.”, “index.html” or anything else. You can then compare two fully qualified URLs to each other.Here’s an example: http://jsfiddle.net/jfriend00/M7mNF/ that shows how it makes a fully qualified URL out of anything.
I can’t promise that it does this in every browser, but I’ve never seen any other behavior.