Results 1 to 5 of 5

Thread: Looking for script (javascript?) to display page directory

  1. #1
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Looking for script (javascript?) to display page directory

    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    Just put this script in the body of your page, where you want the directory name displayed:

    Code:
    <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:

    HTML Code:
    <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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Thanks John, that script works great!

    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

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    One thing that you will have to configure, the extension used by this page (red in the below updated version):

    Code:
    <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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2007
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up John, you're the man! Thanks so much... that works perfectly!

    Thanks, Thanks, Thanks!!!! ))

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •