Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    'A HREF' question

    i have the following line of code:

    document.write("<BR><A HREF=" + aFile.Path + " TARGET=_blank>" + aFile.Path + "</A>")

    the second aFile.Path lists the path of the file just fine.

    problem: the first aFile.Path I want to point to the path as a hyperlink. it lists the path up until the first space, at which point in cuts off the rest of the path. example: folder called "Example Folder" only shows "...\Example", thus it doesn't point appropriately. any help or suggestions would be appreciated. i am new to javascript. thanks.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using location.host.

    eg:
    Code:
    document.write("<BR><A HREF=" +location.host+ aFile.Path + " TARGET=_blank>" + aFile.Path + "</A>")
    .....Willy

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Don't forget to escape().
    Code:
    document.write("<BR><A HREF=" + location.host + escape(aFile.Path) + " TARGET=_blank>" + aFile.Path + "</A>")

  • #4
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thank you for the suggestions, but i'm not having success with either.

    when i include location.host, the path of aFile doesn't print.

    when i include the escape(), nothing prints.

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I wonder if instead of escape(), you were to use urlencode()...

    Try that and let us know what happens,
    Sadiq.

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Encoding the url as Sadiq suggested is mandatory if the text comes from a user input and you want to avoid the possibility of cross site scripting but another basic problem is the fact that you left off the QUOTE marks that should surround ALL html properties. Yes, I realize the browsers will accept unquoted properties but I also know that any time there's an embedded space or other unusual character in that text this is the kind of problem that results.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If this is not hosted but rather being used locally.
    location.host will obviously not work.

    example: folder called "Example Folder" only shows "...\Example",
    .....Willy

  • #8
    Senior Coder
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    1,063
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Roy's got it I think.

    document.write("<BR><A HREF='" + aFile.Path + "' TARGET='_blank'>" + aFile.Path + "</A>")
    Shawn

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,960
    Thanks
    0
    Thanked 236 Times in 233 Posts
    That's right. But double quotes is recommended to use in attribute values.

    document.write('<br /><a href="' + aFile.Path + '" target="_blank">' + aFile.Path + '</a>')


  •  

    Posting Permissions

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