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

    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'
     
    Turbo, Oct 30, 2006
    #1
    1. Advertising

  2. Re: How to get absolute uri by combining the baseuri and the relativeuri in an html page?

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

  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.

    On Oct 30, 10:03 pm, Michael Winter <> wrote:
    > 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
     
    Turbo, Nov 1, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pavel
    Replies:
    2
    Views:
    1,732
    Peter Flynn
    Aug 4, 2004
  2. etheriau
    Replies:
    1
    Views:
    701
    Pavel
    Aug 23, 2004
  3. Replies:
    3
    Views:
    575
    Rad [Visual C# MVP]
    Dec 1, 2006
  4. App Ra
    Replies:
    0
    Views:
    286
    App Ra
    Oct 19, 2006
  5. Replies:
    0
    Views:
    98
Loading...

Share This Page