JavaScript DHTML/GUI Components/Navigation Bar

Материал из Web эксперт
Перейти к: навигация, поиск

A Graphical Navigation Bar

   <source lang="html4strict">

<HTML> <HEAD> <TITLE>Navigation Bar</TITLE> <SCRIPT LANGUAGE="JavaScript">

</SCRIPT> </HEAD> <BODY bgColor="white"> <MAP NAME="navigation"> <AREA SHAPE="RECT" COORDS="25,80,66,116" HREF="javascript:goNext()"> <AREA SHAPE="RECT" COORDS="24,125,67,111" HREF="javascript:goPrev()"> </MAP> <IMG SRC="http://www.wbex.ru/style/logo.png" HEIGHT=240 WIDTH=96 BORDER=0 USEMAP="#navigation"> </BODY> </HTML>


      </source>
   
  


Frameset navigation bar

   <source lang="html4strict">

/* Examples From JavaScript: The Definitive Guide, Fourth Edition Legal matters: these files were created by David Flanagan, and are Copyright (c) 2001 by David Flanagan. You may use, study, modify, and distribute them for any purpose. Please note that these examples are provided "as-is" and come with no warranty of any kind. David Flanagan

  • /

<script> // The function is invoked by the Back button in our navigation bar. function go_back() {

   // First, clear the URL entry field in our form.
   document.navbar.url.value = "";
   // Then use the History object of the main frame to go back.
   parent.frames[0].history.back();
   // Wait a second, and then update the URL entry field in the form
   // from the location.href property of the main frame. The wait seems
   // to be necessary to allow the location.href property to get in sync.
   setTimeout("document.navbar.url.value = parent.frames[0].location.href;",
              1000);

} // This function is invoked by the Forward button in the navigation bar. // It works just like the one above. function go_forward() {

   document.navbar.url.value = "";
   parent.frames[0].history.forward();
   setTimeout("document.navbar.url.value = parent.frames[0].location.href;",
              1000);

} // This function is invoked by the Go button in the navigation bar, and also // when the form is submitted (when the user hits the Return key). function go_to() {

   // Just set the location property of the main frame to the URL
   // that the user typed in.
   parent.frames[0].location = document.navbar.url.value;

} </script>

<form name="navbar" onsubmit="go_to(); return false;"> <input type="button" value="Back" onclick="go_back();"> <input type="button" value="Forward" onclick="go_forward();"> URL: <input type="text" name="url" size="50"> <input type="button" value="Go" onclick="go_to();"> </form>


      </source>
   
  


Navigation Trail Library

   <source lang="html4strict">
<html>

<body> <script> // Navigation Trail Library (trail.js) // by Danny Goodman (http://dannyg.ru) // From "DHTML Cookbook" (O"Reilly) by Danny Goodman // Copyright 2003 Danny Goodman. All Rights Reserved.

var trailMenu = new Object(); trailMenu["catalog"] = "Product Line"; trailMenu["economy"] = "Budget"; trailMenu["deluxe"] = "Luxury"; trailMenu["export"] = "Export Only"; trailMenu["support"] = "Product Support"; trailMenu["faq"] = "Frequently Asked Questions"; trailMenu["downloads"] = "Free Downloads"; trailMenu["manuals"] = "Manuals"; function makeTrailMenu() {

   var parseStart, volDelim, parseEnd;
   var output = "";
   var linkStyle = "color:#339966";
   var path = location.pathname;
   var separator = " » ";
   var re = /\\/g;
   path = path.replace(re, "/");
   var trail = location.protocol + "//" + location.hostname;
   var leaves = path.split("/");
   if (location.protocol.indexOf("file") != -1) {
       parseStart = 1;
       volDelim = "/";
   } else {
       parseStart = 0;
       volDelim = "";
   }
   if (leaves[leaves.length-1] == "" || leaves[leaves.length-1] == "index.html" || leaves[leaves.length-1] == "default.html") {
       parseEnd = leaves.length -1;
   } else {
       parseEnd = leaves.length;
   }
   for (var i = parseStart; i < parseEnd; i++) {
       if (i == parseStart) {
           trail += "/" + leaves[i] + volDelim;
           output += "<a href="" + trail + "" style="" + linkStyle + "">";
           output += "Home";
       } else if (i == parseEnd - 1) {
           output += document.title;
           separator = "";
       } else {
           trail += leaves[i] + "/";
           output += "<a href="" + trail + "" style="" + linkStyle + "">";
           output += trailMenu[leaves[i]];
       }
       output += "</a>" + separator;
   }
   output += "";
   return output;

} document.write(makeTrailMenu()); </script> </body> </html>

      </source>