SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert relative path to absolute

    I have a javascript function that requries the absolute path to an image but I don't have the absolute path avaliable, only the relative path. Is thre a way to convert the relative path to an absolute path in javascript to solve this?

    Thanks.

  2. #2
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if I understand correctly, but couldn't you just call the ID of the image object and convert the position attribute to absolute?

    eg.

    var imgObj = document.images['myImg'];
    imgObj.style.position='ABSOLUTE';

    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Nanaimo, BC, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think he's talking about abs positioning, he wants the absolute URL.

    ie: http://yoursite.com/image.gif
    instead of just
    image.gif

    couldn't you just make a link that goes to the relative path, then it would show the entire path in the address bar.

    ie: <a href="image.gif">

    that would take you to the image and show the URL... or you could just right-click it.

    I'm not sure if I understand your problem though.

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is that I am using a javascript script that does some things with images. The problems is that it needs the full path to the images for some reason to work (no idea why). The problem is that I don't have the full path to the image because it depends upon where the file is on the directory as to where the images are. So what I need to do is convert ./image.gif into www.domain.com/path/to/image.gif in javascript.

  5. #5
    SitePoint Evangelist pip's Avatar
    Join Date
    Jun 2001
    Location
    Cape Town, South Africa
    Posts
    548
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My apologies for the stupid reply, but I think I might try again.

    I place all my images in one image folder ie. http://www.mydom.co.za/images/,

    and therefore never call an image using dots infront of the forward slash. To go all the way back to the very first image folder, I type <IMG SRC="/images/img.gif">.

    No matter where the page is on my domain, just a forward slash infront of the image takes it right back to the root, then calls the images directory.

    But if your image isn't always going to be in the same folder, then I cannot be 100% sure. I know to get the actual directory path of an image you'd use mapPath("imgname.gif");
    - Pip
    ---------------------------------------------------------------------------------
    Nothing takes the taste out of peanut butter quite like unrequited love.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, that is the problem the images can't be in the same directory and thus need to be relative. Guess i will have to keep looking.

    Thanks for the help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •