www.webdeveloper.com
Results 1 to 5 of 5

Thread: breadcrumb javascript not working

  1. #1
    Join Date
    Apr 2007
    Posts
    30

    Question breadcrumb javascript not working

    i found this script on webreference and deployed it but is is not displaying the breadcrumbs.
    i saved the following code in a crumb.js file
    Code:
    function breadcrumbs(){
      sURL = new String;
      bits = new Object;
      var x = 0;
      var stop = 0;
      var output = "<a href="\"/\"">Home</a>  >  ";
      sURL = location.href;
      sURL = sURL.slice(8,sURL.length);
      chunkStart = sURL.indexOf("/");
      sURL = sURL.slice(chunkStart+1,sURL.length)
      while(!stop){
        chunkStart = sURL.indexOf("/");
        if (chunkStart != -1){
          bits[x] = sURL.slice(0,chunkStart)
          sURL = sURL.slice(chunkStart+1,sURL.length);
        }else{
          stop = 1;
        }
        x++;
      }
      for(var i in bits){
        output += "<a href="\"";" for="" output="" bits="">" + bits[i] + "</a>  >  ";
      }
      document.write(output + document.title);
    }
    i then declared the script in the header tag
    HTML Code:
    <script language="JavaScript" type="text/javascript" src="js/crumb.js"></script>
    the following lines i inserted into a div tag where i want it to appear

    HTML Code:
    <div id="bread"><script language="JavaScript">
    <!--
    breadcrumbs();
     -->
    </script>
    </div>

  2. #2
    Join Date
    Apr 2010
    Location
    Oslo, Norway
    Posts
    89
    I'm a little confused about your use of quotes....What exactly is it you wish to output in your line
    Code:
    output += "<a href="\"";" for="" output="" bits="">" + bits[i] + "</a>  >  ";
    Can you provide me with a sample of line of desired output here?
    - Spinner
    Producer, Developer, Gamer, Father and Husband.

    Spinners Web-development blog

  3. #3
    Join Date
    Apr 2010
    Location
    Oslo, Norway
    Posts
    89
    I am going to stick my neck out and GUESS what you are after here.
    How about something like this?


    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<title>Breadcrumbs</title>
    	<script language="JavaScript" type="text/javascript">
    		function breadcrumbs(){
    			sURL = new String;
    			bits = new Object;
    			var x = 0;
    			var stop = 0;
    			var output = "<a href='/'>Home</a>  >  ";
    			sURL = location.href;
    			sURL = sURL.slice(8,sURL.length);
    			chunkStart = sURL.indexOf("/");
    			sURL = sURL.slice(chunkStart+1,sURL.length)
    			while(!stop){
    				chunkStart = sURL.indexOf("/");
    				if (chunkStart != -1){
    					bits[x] = sURL.slice(0,chunkStart)
    					sURL = sURL.slice(chunkStart+1,sURL.length);
    				}
    				else{
    					stop = 1;
    				}
    				x++;
    			}
    			for(var i in bits){
    				output += "<a href='\\";
    				var t=0;
    				for (t=0;t<=i ;t++ ){
    					output+=bits[t]+'/';
    				}
    				output+="'>" + bits[i] + "</a>  >  ";
    			}
    			document.write(output + document.title);
    		}
    	</script>
    </head>
    <body>
    	<script language="JavaScript" type="text/javascript">
    		breadcrumbs();
    	</script>
    </body>
    </html>
    That said, I would not use document.write, I'd manipulate a DOM-element in stead....Oh well...Do you understand this script, or are you just trying to use it?
    - Spinner
    Producer, Developer, Gamer, Father and Husband.

    Spinners Web-development blog

  4. #4
    Join Date
    Apr 2010
    Location
    Oslo, Norway
    Posts
    89
    Here you are, without any document.write at all....

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<title>Breadcrumbs</title>
    	<script language="JavaScript" type="text/javascript">
    		function breadcrumbs(){
    			sURL = new String;
    			bits = new Object;
    			var x = 0;
    			var stop = 0;
    			var output = "<a href='/'>Home</a>  >  ";
    			sURL = location.href;
    			sURL = sURL.slice(8,sURL.length);
    			chunkStart = sURL.indexOf("/");
    			sURL = sURL.slice(chunkStart+1,sURL.length)
    			while(!stop){
    				chunkStart = sURL.indexOf("/");
    				if (chunkStart != -1){
    					bits[x] = sURL.slice(0,chunkStart)
    					sURL = sURL.slice(chunkStart+1,sURL.length);
    				}
    				else{
    					stop = 1;
    				}
    				x++;
    			}
    			for(var i in bits){
    				output += "<a href='\\";
    				var t=0;
    				for (t=0;t<=i ;t++ ){
    					output+=bits[t]+'/';
    				}
    				output+="'>" + bits[i] + "</a>  >  ";
    			}
    			output+=document.title;
    			document.getElementById('div_for_crumbs').innerHTML=output;
    		}
    	</script>
    </head>
    <body onload='breadcrumbs()'>
    	<div id='div_for_crumbs'></div>
    </body>
    </html>
    - Spinner
    Producer, Developer, Gamer, Father and Husband.

    Spinners Web-development blog

  5. #5
    Join Date
    Apr 2007
    Posts
    30
    Quote Originally Posted by Spinner View Post
    I am going to stick my neck out and GUESS what you are after here.
    How about something like this?


    Code:
    <!DOCTYPE html>
    <html>
    <head>
    	<title>Breadcrumbs</title>
    	<script language="JavaScript" type="text/javascript">
    		function breadcrumbs(){
    			sURL = new String;
    			bits = new Object;
    			var x = 0;
    			var stop = 0;
    			var output = "<a href='/'>Home</a>  >  ";
    			sURL = location.href;
    			sURL = sURL.slice(8,sURL.length);
    			chunkStart = sURL.indexOf("/");
    			sURL = sURL.slice(chunkStart+1,sURL.length)
    			while(!stop){
    				chunkStart = sURL.indexOf("/");
    				if (chunkStart != -1){
    					bits[x] = sURL.slice(0,chunkStart)
    					sURL = sURL.slice(chunkStart+1,sURL.length);
    				}
    				else{
    					stop = 1;
    				}
    				x++;
    			}
    			for(var i in bits){
    				output += "<a href='\\";
    				var t=0;
    				for (t=0;t<=i ;t++ ){
    					output+=bits[t]+'/';
    				}
    				output+="'>" + bits[i] + "</a>  >  ";
    			}
    			document.write(output + document.title);
    		}
    	</script>
    </head>
    <body>
    	<script language="JavaScript" type="text/javascript">
    		breadcrumbs();
    	</script>
    </body>
    </html>
    That said, I would not use document.write, I'd manipulate a DOM-element in stead....Oh well...Do you understand this script, or are you just trying to use it?
    I am a newbie just trying to use it. thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles