...

View Full Version : 'A HREF' question



moutslay
03-17-2004, 06:46 PM
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.

Willy Duitt
03-17-2004, 06:52 PM
Try using location.host.

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

.....Willy

Choopernickel
03-17-2004, 07:05 PM
Don't forget to escape().

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

moutslay
03-17-2004, 07:17 PM
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.

sad69
03-17-2004, 07:54 PM
I wonder if instead of escape(), you were to use urlencode()...

Try that and let us know what happens,
Sadiq.

Roy Sinclair
03-17-2004, 08:09 PM
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.

Willy Duitt
03-17-2004, 08:22 PM
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

shlagish
03-18-2004, 01:25 AM
Roy's got it I think.

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

glenngv
03-18-2004, 03:05 AM
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>')



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum