What are the Netscape-Mozilla equivalents?

S

Simba

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>
 
L

Lasse Reichstein Nielsen

//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
 
D

DU

Simba said:
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
 
R

Richard Cornford

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top