|
Q1369 How can I easily extract the filename from a URL?
irt.org | Knowledge Base | JavaScript | Link | Q1369 [ previous next ]
Q1369 How can I easily extract the filename from a URL?
The following was supplied by Joe Barta:
To extract the filename only (no extension) try this...
function DocNameExtract()
{
wholeurl = window.location.href;
x = wholeurl.length;
while((wholeurl.substring(x,x-1)) != "."){ x--; } clipend = x;
while((wholeurl.substring(x,x-1)) != "/"){ x--; } clipstart = x;
return wholeurl.substring(clipend-1,clipstart);
}
|
The function returns the file name. You can then insert it into an alert box or whatever...
To extract the filename with the extension try this...
function DocFileNameExtract()
{
wholeurl = window.location.href;
x = wholeurl.length;
while((wholeurl.substring(x,x-1)) != "/"){ x--; } clipstart = x;
return wholeurl.substring(wholeurl.length,clipstart);
}
|
|
|
Copyright © 1996-2009 irt.org, All Rights Reserved.