PDA

View Full Version : Looking for script (javascript?) to display page directory



mana7
01-28-2007, 03:59 AM
Hello,

I am looking for a way to display the name of the directory (folder) that the current (active) page resides in. I want to use this script in a Dreamweaver template, so that each web page based on that template displays the name of the directory (folder) that that page (file) resides in. I hope that makes sense! I have been searching online for such a script without luck. I hope you can help!

I would prefer not to resort to a server-side script.

Thanks,
Larry

jscheuer1
01-28-2007, 04:48 AM
Just put this script in the body of your page, where you want the directory name displayed:


<script type="text/javascript">
function disp_current_directory(){
var dirs=window.location.href.split('/'),
cdir=dirs[dirs.length-2];
document.write(cdir);
}
disp_current_directory();
</script>

Example:


<div>The current directory is: <script type="text/javascript">
function disp_current_directory(){
var dirs=window.location.href.split('/'),
cdir=dirs[dirs.length-2];
document.write(cdir);
}
disp_current_directory();
</script></div>

mana7
01-28-2007, 06:06 AM
Thanks for the quick reply John.
This code works great!

I do have 2 followup questions....

Is it possible to add to this script so that:

A) the directory name is displayed in ALL CAPS ?

B) there is a hyperlink from the displayed directory name to the page which has the same name as the directory and is in that directory

Thank you, Thank you!
Larry

jscheuer1
01-28-2007, 07:17 AM
One thing that you will have to configure, the extension used by this page (red in the below updated version):


<script type="text/javascript">
function disp_current_directory(){
var ext='htm';
var dirs=window.location.href.split('/'),
cdir=dirs[dirs.length-2];
document.write('<a href="'+cdir+'.'+ext+'">'+cdir.toUpperCase()+'<\/a>');
}
disp_current_directory();
</script>

mana7
01-28-2007, 07:40 AM
Thanks, Thanks, Thanks!!!! :)))