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

M

Michael Winter

Turbo said:
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
 
T

Turbo

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.
 

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,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top