Javascript function that makes an href uniform/consistent?

R

Robert Oschler

Is there a Javascript function, or library, that will take a URL and make it
uniform/consistent?

Something that will resolve all relative pathing and the current domain and
protocol and return a uniform URL? Like the realpath() function in PHP?

Thanks.
 
G

Grant Wagner

Is there a Javascript function, or library, that will take a URL and make it
uniform/consistent?

Something that will resolve all relative pathing and the current domain and
protocol and return a uniform URL? Like the realpath() function in PHP?

location.href and location.pathname seem to do that by default.

I get the same answer to alert(location.pathname) whether the path is:

http://server/path/to/file.html or
http://server/path/to/../../path/to/file.html

Tested browsers:
IE 6.0.2900
Firefox 1.0.6
Opera 7.54u2
Opera 8.02

Note that of the browsers listed above, only IE retains the original
(relative) path on the address bar. However, that may change in IE7,
where they are going to a global URL object which will (supposedly) be
used to provide a consistent, secure, validated URL to all components.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top