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

Discussion in 'Javascript' started by Turbo, Oct 30, 2006.

  1. Turbo

    Turbo Guest

    Turbo, Oct 30, 2006
    #1
    1. Advertisements

  2. 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
     
    Michael Winter, Oct 30, 2006
    #2
    1. Advertisements

  3. Turbo

    Turbo Guest

    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.
     
    Turbo, Nov 1, 2006
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.