HTML
  Home arrow HTML arrow Page 3 - Background Images for a Menu for All Brows...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Background Images for a Menu for All Browsers
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-06-17

    Table of Contents:
  • Background Images for a Menu for All Browsers
  • Using Background Images
  • Changes to the Code
  • Review of the Project

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Background Images for a Menu for All Browsers - Changes to the Code


    (Page 3 of 4 )

    We have to make some changes to the code in order to support the images. For simplicity, we shall make the changes to affect only the drop down and sub menus and not the main menu. We begin with the CSS. Change all the following expressions in the CSS:

    background-color:brown

    to

    background-image:url("norm.gif");

    So, instead of a background color, we have a background image for the cells. Add the following expression next to each of the above code in the CSS:

    background-repeat: repeat-x;

    This expression causes the image to repeat along the cell (horizontally). So it does not matter how wide the table cell is; you will have a bar as the background of the cell due to the "repeat-x" property.

    Let us see the changes to be made to the JavaScript code. Replace all the "backgroundColor" properties with "backgroundImage." Replace all the "brown" values with "url('norm.gif')." Replace all the "firebrick" values with "url('ov.gif')."

    For the non-image code, the toChoose() function was:

    function toChoose(ID)

    {

    currCellBgColor = document.getElementById(ID).style.backgroundColor; //background color of the current cell

     

    if ((currCellBgColor == "firebrick")||(currCellBgColor == "#b22222")||(currCellBgColor == "rgb(178, 34, 34)"))

    subMenuJustClicked = true;

    }


    Now with the images, it is:


    function toChoose(ID)

    {

    currCellBgColor = document.getElementById(ID).style.backgroundImage; //background color of the current cell

     

    if (currCellBgColor == "url('ov.gif')")

    subMenuJustClicked = true;

    }


    Note that in the if-condition we have no longer taken into consideration the peculiarity of any browser. The expression "url('ov.gif')" in the if-condition is recognized by all of the five major browsers we use for testing. The other statements in the toChoose() function remain the same; only the test of the if-condition has changed.

    That is all we need for the changes. I tested the code and it worked with the five browsers (Internet Explorer, Mozilla Firefox, Netscape, Opera and Safari). There is just a small problem with Opera. When you open the page with Opera and then move the mouse pointer over a main menu item, the default image (norm.gif) will go away, but you will not see the onmouseover image (ov.gif). This happens only once, for the first time; after that it does not happen again. After that you will be seeing the ov.gif image for any menu item (main menu, drop down menu or sub menu) that the mouse pointer goes over. This problem is negligible. So we will ignore it.

    I want you to note that the code with background images does not really have any code segment specialized for any particular browser. The non-image code had the if-statement with bits for different browsers. This if-statement for the image code does not have these bits. So we can say that with the image code, we have attained our goal of having code that works for all browsers, without any code segment specialized for any browser. The trouble is that there is a condition, which is that you need to have background images and not background colors.

    The complete image code can be downloaded from here:

    versatileCommonMenuImg.ZIP

    The image files are included. After downloading, unzip in one directory and double click the HTML file.

    More HTML Articles
    More By Chrysanthus Forcha


     

    HTML ARTICLES

    - Comparing Browser Response to Active Client ...
    - Testing Browser Response to Active Client Pa...
    - Active Client Pages: Completing the Code for...
    - ACP and Browsers: Setting up an Example
    - How Browsers Respond to Active Client Pages
    - Completing a Tree with Active Client Pages
    - HTML Form Verification and ACP
    - Building an ACP Tree
    - Completing an ACP 3D HTML Table Image Gallery
    - Building an ACP 3D HTML Table Image Gallery
    - A Multiple Page Image Gallery with Active Cl...
    - Building an Image Gallery with Active Client...
    - Concluding a Menu for All Browsers
    - A Vertical Menu for All Browsers
    - Downloading Long HTML Pages with ACP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek