Re: JavaScript / CSS Wizards Please Help

On Tuesday 04 December 2001 23:09, Jim Ley wrote:
|   "Bailey, Bruce":
|   > The vendor is using a public domain menu which I could NOT get to use
|   > relative units.  A discussion and download links to this file
|
|   (fw_menu.js)
|
|   > can be found at URL:
|
|   Okay, brief look:
|
|   Consider the FIND function:
|
|   function FIND(item) {
|    // If we define the "all" attribute, use it (IE only)
|    if (document.all) return(document.all[item]);
|    // If we did not have the "all" attribute, try the getElementById method
|    //  Both Netscape 6/Mozilla and IE support this, but only Mozilla will
|   make it
|    //  this far.
|    if (document.getElementById) return(document.getElementById(item));
|    // We did not have either way of searching.
|    return(false);
|   }
|

function above is written in a wrong way.
It should be:

// once per JS file
var d=document;
var DOM=(d.getElementById)?true:false;
var MSIE=(d.all)?true:false;
var NN4=(d.layers)?true:false;

function FIND(item) 
{
  if (DOM)
    {  return(document.getElementById(item)  }
  else 
  if (MSIE)
    {      return(document.all[item]     }
   else 
      if  (NN4)
         {   /* code for NN 4.7 */  }
       else return(false)
}


|   It mentions Mozilla, and IE, lets look at what might happen in other
|   browsers:
|
|   Opera has document.all[1] so it evaluates to true, so Opera will return
|   undefined from that function (despite it supporting DOM1 so gEBI would
|   return the correct element like Mozilla (and Opera should be able to run
|   the script.)

I do not recommend you to support Opera - Opera is very buggy browser.
Anyway, in example above, Opera will go into DOM branch

[...]
|
|   Jim.

BTW: if you are looking for nice-looking, good-working menues, check 
www.intel.com
Their code is somewaht ugly, but works (IIRC even in Opera)

-- 

Vadim Plessky
http://kde2.newmail.ru  (English)
33 Window Decorations and 6 Widget Styles for KDE
http://kde2.newmail.ru/kde_themes.html
KDE mini-Themes
http://kde2.newmail.ru/themes/

Received on Wednesday, 5 December 2001 06:13:20 UTC