SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Any javascript "bread crumbs" scripts?

    I'd like to do a "bread crumbs" type of navigation for my web pages, and my host only lets me use perl. Can anyone let me know of a bread crumbs script that is based on javascript?

    The user should see something like this:

    home >> directory1 >> directory2 >> current directory
    I guess the javascript would need to take a look at the URL and figure out the directory structure and then display it..

    Thanks!

    PS - I did look in hotscripts, but was unable to find anything.
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Premaking this would be difficult as everyones directory structure would be different. Unless of course you had a multi-dimentional array setup to track the movements and display the proper crumbs.

    I know I couldn't find anythin premade as this is usually done with a server side language.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    Grumpy Mole Man Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The following code is not perfect but should provide you with a starting point:
    Code:
    <script type="text/javascript">
    // url = document.location;
    url = "http://www.site.com/dir1/dir2/";
    document.write("URL is "+url+"<br><br>");
    urlbits = url.split('/');
    // urlbits[0] is http:
    // urlbits[1] is the site domain
    breadcrumbs = '<a href="/">Home</a> >> ';
    for (i = 3; i < (urlbits.length); i++) {
      if (urlbits[i]) {
        breadcrumbs += '<a href="/'+urlbits[i]+'">'+urlbits[i]+'</a> >>';
      }
    }
    document.write(breadcrumbs);
    </script>

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To be honest forgett javascript for this task. As much as I like it, it is by far one of the worst methods to use when the simplicity of using a server side language would be better.

    Have fun, with it

    PHP Code:
    #!/usr/bin/perl
    ##############################################################################
    # cookie_trail.cgi              Version 1.0                                  #
    # Copyright 2000 Martin Burns   [email]scripts@easyweb.co.uk[/email]                        #
    # Created 19/9/2000             Last Modified 19/9/2000                      #
    ##############################################################################
    # COPYRIGHT NOTICE                                                           #
    # Copyright [and -left] 2000 Martin Burns  All Rights Reserved except as     #
    # provided below.                                                            #
    #                                                                            #
    # CookieTrail may be used and modified free of charge by anyone so long      #
    # as this copyright notice and the comments above remain intact. By using    #
    # this code you agree to indemnify Martin Burns and EasyWeb Design from any  #
    # liability that might arise from it's use.                                  #  
    #                                                                            #
    # This script is released under the GPL.                                     #
    # Selling the code for this program or any derivative work is expressly      #
    # forbidden. A full copy of the GPL can be found in the Code section of      #
    # [url]http://evolt.org.[/url] In all cases copyright and this header must remain       #
    # intact.                                                                    #
    ##############################################################################

    ############################################################################
    # Some useful stuff                                                        #
    ############################################################################

    # Gives better error messages - not that there should be any. A useful way
    # of increasing the size of your error log, anyway
    use diagnostics;

    # Ensures that the case swapping function works in all languages
    # (Exception: Beta-S in German) FOR VERSION 5.004+ only!
    #use locale;

    ############################################################################
    # Define configuration constants                                           #
    ############################################################################

    # $URL_PATH is the path from the top of the URL tree - sticking it in a
    # normal variable for clarity
    $URL_PATH $ENV{'DOCUMENT_URI'};

    $REQUIRE_DIR '/cgi-bin/';

    @
    crumbs='';
    @
    crumbs_path='';
    $html='';
    $TITLE='';

    ############################################################################
    # Get Required subroutines which need to be included.                      #
    ############################################################################

    # Push the $REQUIRE_DIR onto the @INC array for include file directories.

    if ($REQUIRE_DIR ne '') {
        
    push(@INC$REQUIRE_DIR);
    }

    # Require Necessary Routines for this script to run.
    require 'cgi-lib.pl';

    ############################################################################
    # Parse the arguments and output HTTP headers                              #
    ############################################################################


    if (!&ReadParse) {
       print &
    PrintHeader"<!-- script parse error ($!)-->";
    } else {
      print &
    PrintHeader;
    }

    $TITLE $in{'title'};
    if (
    $TITLE) { $TITLE '-&gt; '.$TITLE};

    ############################################################################
    # Parses the path and dumps any trailing filenames (eg 'index.shtml')      #
    ############################################################################

    @crumbs split(/\//, $URL_PATH);
    if($URL_PATH =~ /./) {
        
    pop(@crumbs);
    }


    ############################################################################
    # Output the link                                                          #
    ############################################################################
    for $i .. $#crumbs) {
        
        # Each part of the link has to contain all the previous parts
        # separated by slashes of course
        
    $a $i 1;
        
    $crumbs_path[$i] = $crumbs_path[$a].'/'.$crumbs[$i];
     
        
    # Capitalise the first letter of each part
        
    $crumbs[$i] = "\u$crumbs[$i]";
     
        
    # using qq|foo| to get out of the way of quotes and slashes in HTML
        # using qq|foo|, not q|foo| to enable interpolation
        
    $html .= qq|-&gt; <a href="$crumbs_path[$i]/" class="crumb">$crumbs[$i]</a> |;
        }
        
    $html .= $TITLE;
    print 
    "$html\n"


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
  •