What are the Netscape-Mozilla equivalents?

Discussion in 'Javascript' started by Simba, Oct 18, 2003.

  1. Simba

    Simba Guest

    Hi,

    I've written some javascript routines for Internet Explorer and Opera.
    Could you tell me the Netscape and Mozilla equivalents?

    Thanks

    -------------------------

    //this works with Opera, not with Netscape and Mozilla:

    var menuOpened = false;
    var whatMenu = new Object();

    function showMenu(menu){ //menu is the id of a DIV element

    if ( menu == null ) return;

    if (!menuOpened){
    menu.style.visibility='visible';
    menuOpened = true;
    whatMenu = menu;
    }
    else{
    menu.style.visibility='hidden';
    menuOpened = false;
    whatMenu = null;
    }
    }

    -----------------

    //this works only with Internet Explorer and Opera

    var clicksBold = 0;

    function toggleBold(){

    clicksBold++;

    SPANs = document.all.tags("SPAN");

    for (var h = 0; h < SPANs.length; h++){
    x = SPANs[h];
    if (x.className == "aClassName"){
    if ((clicksBold % 2) == 1) x.style.fontWeight = "bold";
    else x.style.fontWeight = "normal";
    }
    }
    }


    -----------------

    colors = new Array("blue","cyan","lightgreen","green","red","orange","yellow","pink","violet","black","gray","white");
    for (var j = 0; j < colors.length; j++){
    document.write("<span style='background-color:" + colors[j] + ";
    height:25; width:25; border-style:solid; border-width:1pt'></span> ");
    }

    //the output is a series of sqares in Internet Explorer and Opera,
    some black lines in Netscape

    --------------------------
    //anID is the ID of a SPAN element

    <select name="leftMargin"
    onchange="anID.style.marginLeft=this.value;">
    ....
    </select>
    Simba, Oct 18, 2003
    #1
    1. Advertising

  2. (Simba) writes:

    > //this works only with Internet Explorer and Opera


    > var clicksBold = 0;

    ....
    > clicksBold++;

    I would use
    var clicksBold = false;
    ...
    clicksBold = ! clicksBold;
    It better models what you want: toggling between on and off.

    > SPANs = document.all.tags("SPAN");

    Use:
    var SPANs = document.getElementsByTagName("SPAN");

    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Oct 18, 2003
    #2
    1. Advertising

  3. Simba

    DU Guest

    Simba wrote:
    > Hi,
    >
    > I've written some javascript routines for Internet Explorer and Opera.
    > Could you tell me the Netscape and Mozilla equivalents?
    >
    > Thanks
    >
    > -------------------------
    >
    > //this works with Opera, not with Netscape and Mozilla:
    >
    > var menuOpened = false;
    > var whatMenu = new Object();
    >
    > function showMenu(menu){ //menu is the id of a DIV element
    >
    > if ( menu == null ) return;
    >
    > if (!menuOpened){
    > menu.style.visibility='visible';


    All 3 browsers and many other W3C DOM 1 compliant browsers (Safari 1.0,
    Konqueror 3.1.x, MSIE 5.x for Mac, MSIE 5+, etc.) all support
    document.getElementById("menu").style.visibility = "visible";
    So, it is best for many reasons to use this manner of coding.

    Using Web standards in your web pages
    http://www.mozilla.org/docs/web-developer/upgrade_2.html

    Updating DHMTL Web pages
    http://devedge.netscape.com/viewsource/2001/updating-dhtml-web-pages/

    > menuOpened = true;
    > whatMenu = menu;
    > }
    > else{
    > menu.style.visibility='hidden';
    > menuOpened = false;
    > whatMenu = null;
    > }
    > }
    >
    > -----------------
    >
    > //this works only with Internet Explorer and Opera
    >
    > var clicksBold = 0;
    >
    > function toggleBold(){
    >
    > clicksBold++;
    >
    > SPANs = document.all.tags("SPAN");


    Again, like Lasse said, best is to use

    spanCollection = document.getElementsByTagName("SPAN");
    which is widely and well supported by W3C DOM 1 compliant browsers.

    >
    > for (var h = 0; h < SPANs.length; h++){
    > x = SPANs[h];
    > if (x.className == "aClassName"){
    > if ((clicksBold % 2) == 1) x.style.fontWeight = "bold";
    > else x.style.fontWeight = "normal";
    > }
    > }
    > }
    >
    >
    > -----------------
    >
    > colors = new Array("blue","cyan","lightgreen","green","red","orange","yellow","pink","violet","black","gray","white");
    > for (var j = 0; j < colors.length; j++){
    > document.write("<span style='background-color:" + colors[j] + ";
    > height:25; width:25; border-style:solid; border-width:1pt'></span> ");


    There is a better alternative here to document.write.


    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
    DU, Oct 18, 2003
    #3
  4. "Simba" <> wrote in message
    news:...
    <snip>
    > for (var j = 0; j < colors.length; j++){
    > document.write("<span style='background-color:" + colors[j] + ";
    >height:25; width:25; border-style:solid;border-width:1pt'></span> ");
    > }

    <snip>

    In addition to what Lasse and DU said, the CSS standard requires that
    length values used with CSS properties should be provided with units
    (px, em, ex, pt, pc, etc or percentages) and Mozilla browsers are
    inclined to take a rather literal attitude towards the interpretation of
    applicable standards. height:25; may be ignored for that reason alone,
    however, the SPAN element is inline and non-replaced so CSS width and
    height properties do not apply to it anyway.

    Richard.
    Richard Cornford, Oct 19, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Peters

    Special character to &abc equivalents

    Colin Peters, May 7, 2005, in forum: ASP .Net
    Replies:
    8
    Views:
    2,282
    =?Utf-8?B?UGF1bCBQYXJraW5zb24=?=
    May 9, 2005
  2. Jeff Thies

    CSS equivalents for attributes

    Jeff Thies, Jul 13, 2004, in forum: HTML
    Replies:
    36
    Views:
    1,273
    Mark Parnell
    Jul 15, 2004
  3. Allen F.
    Replies:
    3
    Views:
    475
    Nathaniel L. Walker
    Feb 9, 2005
  4. Code_Dark

    New to Python; Command equivalents

    Code_Dark, Nov 5, 2003, in forum: Python
    Replies:
    2
    Views:
    429
    Dang Griffith
    Nov 5, 2003
  5. Tshepang Lekhonkhobe

    are there Tomboy and F-Spot equivalents?

    Tshepang Lekhonkhobe, Dec 21, 2006, in forum: Python
    Replies:
    1
    Views:
    269
Loading...

Share This Page