You are here: irt.org | FAQ | JavaScript | Link | Q1369 [ previous next ]
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...
alert(DocNameExtract());
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); }