471,107 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,107 software developers and data experts.

How to get absolute uri by combining the baseuri and the relative uri in an html page?

How to get absolute uri by combining the baseuri and the relative uri
in an html page using javscript?
I am looking for something similar to python's
urlparse.urljoin('baseuri', 'relativeuri');
For example urlparse.urljoin('http://blabla.com/abcd/123','a.html')
will return 'http://blabla.com/abcd/a.html'

Oct 30 '06 #1
2 3941
Turbo wrote:
How to get absolute uri by combining the baseuri and the relative uri
in an html page using javscript?
In the simplest case, strip any characters after the last slash in the
base URI and concatenate the relative URI:

absoluteUri = baseUri.substring(0,
baseUri.lastIndexOf('/') + 1)
+ relativeUri;

For that to succeed, the baseUri must be a canonical, hierarchical URI.
For example, the path component must consist of at least one slash:

//www.example.com/

not

//www.example.com

Normalisation of the resulting URI would be left to whatever's going to
use it - pointless, but harmless, dot-segments will not be removed.

The general case requires much more work, though it's certainly
feasible. It's more likely that you'd want something between the two, if
the above isn't sufficient.

RFC 3986 defines the resolution and normalisation processes.

Mike
Oct 30 '06 #2
hi
thanx for the answer.
But I am a looking for a general one. Thats why I want to use a trusted
library function instead of making my own. Actually I am parsing an
HTML Page and converting relative uris to full uris to store in my
database. That html page could be from anywhere, and therfore, my
function should work for all cases.
Thanx once again for the reply.

On Oct 30, 10:03 pm, Michael Winter <m.win...@blueyonder.co.ukwrote:
Turbo wrote:
How to getabsoluteuriby combining the baseuri and therelativeuri
in an html page using javscript?In the simplest case, strip any characters after the last slash in the
baseURIand concatenate therelativeURI:

absoluteUri = baseUri.substring(0,
baseUri.lastIndexOf('/') + 1)
+ relativeUri;

For that to succeed, the baseUri must be a canonical, hierarchicalURI.
For example, the path component must consist of at least one slash:

//www.example.com/

not

//www.example.com

Normalisation of the resultingURIwould be left to whatever's going to
use it - pointless, but harmless, dot-segments will not be removed.

The general case requires much more work, though it's certainly
feasible. It's more likely that you'd want something between the two, if
the above isn't sufficient.

RFC 3986 defines the resolution and normalisation processes.

Mike
Nov 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joe Cybernet | last post: by
4 posts views Thread by Ken Kast | last post: by
3 posts views Thread by Alexander Fischer | last post: by
24 posts views Thread by Wim Roffal | last post: by
reply views Thread by Flip | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.