MozillaZine

Javascript works in IE but not in Mozilla

Discussion of bugs in Seamonkey
david.robinson
 
Posts: 2
Joined: December 6th, 2002, 2:18 am

Post Posted December 6th, 2002, 2:34 am

Hi,
Can anyone tell me why the following js code fails in Mozilla? In IE it gives me a heirarchical drop-down menu.

I'd like to advise my site users to switch to Mozilla / Phoenix if I can get to the bottom of this one.
Thanks.
Dave

<!--
/**
* Based on Folding Menu Tree
* Dynamic Drive (www.dynamicdrive.com)
* For full source code, installation instructions,
* 100's more DHTML scripts, and Terms Of
* Use, visit dynamicdrive.com
*
* Updated to support arbitrarily nested lists
* by Mark Quinn (mark@robocast.com) November 2nd 1998
*/

var head="display:''"
img1=new Image()
img1.src="../images/fold.gif"
img2=new Image()
img2.src="../images/open.gif"

function change(){
if(!document.all)
return
if (event.srcElement.id=="foldheader") {
var srcIndex = event.srcElement.sourceIndex
var nested = document.all[srcIndex+1]
if (nested.style.display=="none") {
nested.style.display=''
event.srcElement.style.listStyleImage="url(../images/open.gif)"
}
else {
nested.style.display="none"
event.srcElement.style.listStyleImage="url(../images/fold.gif)"
}
}
}

document.onclick=change
//-->

cdn

User avatar
 
Posts: 999
Joined: November 4th, 2002, 5:47 pm
Location: UK

Post Posted December 6th, 2002, 4:40 am

david.robinson wrote:Hi,
Can anyone tell me why the following js code fails in Mozilla? In IE it gives me a heirarchical drop-down menu.


easy

Code: Select all
  if(!document.all)


document.all is proprietary ms

you need to either convert this code to use document.getElementById or find another js script that uses document.getElementById to do the same thing

perhaps : http://www.dynamicdrive.com/dynamicindex1/navigate1.htm

jgraham

User avatar
 
Posts: 558
Joined: November 28th, 2002, 10:20 am
Location: Cambridge, UK

Post Posted December 7th, 2002, 3:12 am

cdn wrote:easy

Code: Select all
  if(!document.all)


document.all is proprietary ms

you need to either convert this code to use document.getElementById or find another js script that uses document.getElementById to do the same thing


As cdn said, document.all is not supported by mozilla - only document.getElementById. But importantly, document.getElementById is also supported by Internet explorer 5/6, so you can write code like:

if(document.getElementById) { //this code for Mozilla / Netscape 6/7 / IE 5/6 / Opera / All other modern browsers
}
elseif(document.all) { // Internet Explorer 4 only
}
elseif(document.layers) { //Netscape 4 only
}
else{ //Browsers that don't support what you're trying to do. Remember to make the page work anyway!
}

That should take care of everything. The above psudo-code may be syntatic rubbish.

david.robinson
 
Posts: 2
Joined: December 6th, 2002, 2:18 am

Post Posted December 7th, 2002, 9:29 am

thanks j

Return to SeaMonkey Bugs


Who is online

Users browsing this forum: No registered users and 1 guest