[Javascript] Dynamic breadcrumbs script

Paul Novitski paul at novitskisoftware.com
Wed Sep 1 14:15:33 CDT 2004


Kevin,

Here's what I think you mean:

The breadcrumbs script you're using provides a hyperlink for each node of 
the current page's URL, like so:

If the complete URL is http://www.something.com/folder1/folder2/pageA.html 
then the script generates a series of breadcrumbs something like this:

1) Home         http://www.something.com/
2) Folder 1     http://www.something.com/folder1/
3) Folder 2     http://www.something.com/folder1/folder2/
4) Page 1       http://www.something.com/folder1/folder2/page1.html

The script is assuming that if you want to back up from the current page to 
its parent folder, you will automatically want to go to the default page 
for that folder.

As you probably know, if you navigate to an URL that terminates in a folder 
name, the server will attempt to deliver a default page in that 
folder.  Typically the server will look for index.html, default.html, 
index.asp, etc., in a particular sequence until it finds a page to deliver; 
your web host or network administrator can tell you exactly what the 
sequence is.  If it can't a default page, and if security allows, the 
server will deliver a folder & file tree branch instead.

I gather that your problem is that you want the breadcrumbs script to 
insert a specific special page name for each folder that is not a typical 
default page name, so that the above breadcrumbs would become:

1) Home         http://www.something.com/apple.html
2) Folder 1     http://www.something.com/folder1/banana.html
3) Folder 2     http://www.something.com/folder1/folder2/cranberry.html
4) Page 1       http://www.something.com/folder1/folder2/page1.html

I can see two ways to go about this.  One would be to modify the 
breadcrumbs script.  If your folder structure is extremely simple you could 
hard-code page names into the script for each level of the for/next loop 
that iterates through the URL nodes.  However, the script would doubtless 
be easier to manage if you created a two-dimensional array, e.g.:

         aPageNames["folder"] = "folder1"
         aPageNames["page"] = "banana.html"
         (for http://www.something.com/folder1/)

         aPageNames["folder"] = "folder1/folder2"
         aPageNames["page"] = "cranberry.html"
         (for http://www.something.com/folder1/folder2/)

         aPageNames["folder"] = "folder3/folder1"
         aPageNames["page"] = "elephant.html"
         (for http://www.something.com/folder3/folder1/)

Then the script could be modified to look up the page name for each folder 
path it's processing in the for/next loop.

Alternatively, if you're planning not to use the server default pages in 
your folders, you could create them as minimal pages containing only 
redirect commands to your desired page names:

         folder1/index.html:
                 redirect to banana.html

         folder1/folder2/index.html:
                 redirect to cranberry.html

         folder3/folder1/index.html:
                 redirect to elephant.html

The redirection can be handled several ways, including:

a) a server-side script such as ASP or PHP can issue a redirect before the 
page is ever downloaded to the client;

b) the index.html page's header can contain a meta refresh tag with a zero 
delay;

c) the index.html page can contain a client-side script (such as JavaScript 
or VBscript) that resets the document.location.href.

I hope at least some of this addresses your situation~

Paul



At 07:19 AM 9/1/2004, Atkins, Kevin D wrote:
>Hi Paul,
>
>Paul,
>
>I am just getting caught up from being on vacation and starting to work
>on this again. Are you able to help/explain this further? The coding
>change you describe is valid, but not what I am trying to do. I guess I
>didn't explain this very clearly. I don't want to write the last nodes
>html file name on screen. I want the node that gets written to have the
>actual full url path including the html page written into the node.
>
>What I am seeing in my testing is like this. I have a home page called
>index.html, the node name gets written as Home, the url of the Home node
>gets written as http://www.something.com/, why is the code dropping
>index.html from the node url?. I want the url of the node to be written
>as http://www.something.com/index.html. By dropping the real html page
>it looks to me that the code assumes all pages in all folders will have
>an index.html file. On my site I have multiple folders and the main page
>in those folders is not called index.html.
>
>On the home page I have 2 url links called test page1 and test page 2.
>Test page 1 is called test-page1.html, found in a folder called page1.
>Test page 2 is called test-page2.html found under folder /page1/page2.
>When test page 1 is selected, the node gets written as Home > Page 1 >
>Test Page 1. The url for the Page 1 node gets written as
>http://www.something.com/page1, the node should be written as
>http://www.something.com/page1/test-page1.html. The same thing happens
>for the next node for test page 2 and so on.
>
>I hope this makes sense? If you can help me further to understand the
>code and make changes I would appreciate it, if not just let me know and
>I will move on. Thanks again.
>
>Kevin Atkins
>Sr. Analyst Flight Operations
>612-727-6732
>
>-----Original Message-----
>From: javascript-bounces at LaTech.edu
>[mailto:javascript-bounces at LaTech.edu] On Behalf Of Paul Novitski
>Sent: Tuesday, August 24, 2004 12:10 PM
>To: [JavaScript List]
>Subject: RE: [Javascript] Dynamic breadcrumbs script
>
>Kevin,
>
>I figured out what you meant by the possessive pronoun "your" in your
>posting: you were thinking that a script you found in the LaTech
>JavaScript
>archives is the collective child of the current listserve
>membership.  Instead, this listserve is a loose collection of
>individuals
>each contributing their own bits to the collective soup.  Any script
>contributed by a listserve member is the intellectual child of that
>member,
>and may not be known to or understood by other members.  Not a critical
>distinction, but one worth noting for future reference.
>
>I suspect that the script you're referring to is the dynamic breadcrumbs
>
>script written by Harry Love, as described in
>https://lists.latech.edu/pipermail/javascript/2002-August/004019.html
>
>His script is located at
><http://healthlinks.washington.edu/scripts/dynacrumbs.js>http<http://hea
>lthlinks.washington.edu/scripts/dynacrumbs.js>://healthlinks.washington.
>edu/scripts/dynacrumbs.js
>
>Quickly perusing Harry's script, I see that it creates breadcrumb links
>in
>the format
>          Base > node > node > node
>from the current page's URL.
>
>In a quick test, I didn't see the final node (the html file itself)
>included in the breadcrumb array, regardless of its file name
>(index.html
>or dynacrumbs.html).  It seems clear that Harry was deliberately
>omitting
>that node.
>
>The final for/next loop of the script begins this way (where urlL is the
>
>number of nodes in the URL):
>
>          if(urlL>2)
>          {
>                  for(x=startPoint+1;x<urlL;x++)
>                  {
>                          if(x<urlL-1)
>
>In other words, that last if-test is excluding the final node of the
>array.  If you change that last line to:
>
>                          if(x<urlL)
>
>then your html file name will be displayed.  You might wish to tweak the
>
>display by deleting the file extension, etc.
>
>Good luck,
>Paul
>
>
>At 07:18 AM 8/24/2004, Atkins, Kevin D wrote:
> >Paul,
> >
> >Thanks for the reply. The script I found and am trying to use comes
>from
> >your site called Dynamic Breadcrumbs, I am attaching the code I am
> >using. I can also send a few test pages to see how I have added in the
> >javascript code to call the external breadcrumb file.
> >
> >You can't view any of the files on my site because it is a secured
> >Intranet site that only employees are allowed to login into and view. I
> >am hoping you don't need to view the actual pages on my site to help me
> >modify the script?
> >
> >I will try to describe my site and file structure in case this can help
> >to understand the layout and how I think the code is acting. I share a
> >server instance with another department, we both have a separate
>virtual
> >server to store our files. An example of my area is
> >www.something.com/fop at this level is my index.html page.
> >
> >I changed the var startname in the breadcrumb script to Home. When the
> >breadcrumb code runs it rights out Home > correctly on my index.html
> >page. The url assigned is www.something.com/fop, it does not show
> >index.html in the url link as the page to load. Clicking the Home
> >breadcrumb reloads the index.html page, leading me to think the
> >breadcrumb code thinks every breadcrumb link will have an index.html
> >file in the folders or directories.
> >
> >I created 2 test links on my test index page, the folder structure is
> >/fop/page1 and /fop/page1/page2. When Test page 1 is selected on the
> >index.html page the breadcrumb gets written ok as Home > Page1 > Test
> >Page 1. The breadcrumb url link for Test page1 is written as
> >www.something.com/fop/page1/. If you click the Page1 breadcrumb url it
> >does not reload test page1 called test-page1.html. Instead it displays
>a
> >file list of all files in the page1 folder. I think because it does not
> >see an index.html page in the page1 folder.
> >
> >What I am trying to get is the breadcrumb url to be written as
> >www.something.com/fop/page1/test-page1.html. The same thing happens for
> >test page 2. Is there a way for the breadcrumbs.js file to actually
>read
> >the url of the page you are on and write that into the breadcrumb url
> >link and not assume it is index.html?
> >
> >I am sorry if my explanation doesn't make sense, I hope it does? If you
> >can't help because you can't see the files in actual use, that's ok, I
> >will just have to look for another script somewhere. Thanks for your
> >time.
> >
> >Kevin Atkins
> >Sr. Analyst Flight Operations
> >612-727-6732
>
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list