On Wed, 7 Apr 2004 10:03:13 +0200, "Jakob Lund Krarup"
<ne************@jake.dk> wrote:
"William Starr Moake" <ws*****@yahoo.com> skrev i en meddelelse
news:dv********************************@4ax.com.. . Is there a script to convert image file paths from absolute to just
img src="imagename.jpg"? This is for an IE-based WYSIWYG editor. The
doImage execCommand produces an absolute file path, which then must be
shortened manually before the user uploads the page to his web host.
Hi William
The path to the file will usually be interspersed with "/" or "\" signs to
show where the different folders are in the path.
E.g.: "graphics/myItems/image.gif"
You can split that URL using the String objects split() method, and then use
the last element in the resulting array:
//This function returns only the filename from a string containing a path
function getFileName(path)
{
var pathArray = path.split("/");
return pathArray[pathArray.length-1];
}
Try it out at: http://www.jake.dk/programmering/javascript/forWilliam
Kind regards - Jakob
Thanks for trying, but I can't get the script to work.
From file://C:\Windows\Desktop\Images\logo.gif it returns:
C:\Windows\Desktop\Images\logo.gif, simply removing the file://
I tried varying the minus number, but nothing worked.
I need a script that will return img src="logo.gif" to be placed in
the page source code when an image is inserted. The IE doImage
function by itself returns the full image path, which is a nightmare
to deal with for the user of a WYSIWYG editor.