Jump to content

firefox won't display it, ie will


alejandro52

Recommended Posts

I'm trying to create a dynamic menu but there are some dom elements that don't work with firefox. can someone show what dom elements i have to change to work for both?

Here is the code

<script LANGUAGE = "JAVASCRIPT">
function loading(){
var i;
var d;
for (i=1;i<8;i++){
var d=document.getElementById(i);
d.style.top=i*38;
}
}
window.onload = loading;

function dropdown(id){
var img=document.getElementById('img'+id);
var d_this = document.getElementById(id);
var sub_menu = document.getElementById('sub'+id);
if (img.alt=="down_arrow"){
	move_down(id,img,d_this,sub_menu);
}else if (img.alt=="up_arrow"){
move_up(id,img,d_this,sub_menu);
}
}


function move_up(id_others,img,d_this,sub_menu){
img.src="images/down_arrow.gif";
img.alt="down_arrow";
for(i=1;i<8;i++){
if ((i)!=id_others){
if((i)>id_others){
d=document.getElementById(i);
d.style.top=(i*38);
}
}
sub_menu.style.visibility='hidden';
}
}



function move_down(id_others,img,d_this,sub_menu){
var hei=parseInt(sub_menu.currentStyle.height);
var i;
img.src="images/up_arrow.gif";
img.alt="up_arrow";
for(i=1;i<8;i++){
var img_next=document.getElementById('img'+i);
var sub_next=document.getElementById('sub'+i);
if ((i)!=id_others){
	if(img_next!=null&&img_next.alt=="up_arrow"){dropdown(i)}
	if((i)>id_others){
	var d=document.getElementById(i);
	d.style.top=i*38+hei;	
	}
}
}
sub_menu.style.visibility='visible';
sub_menu.style.top=parseInt(d_this.currentStyle.height)+parseInt(d_this.currentStyle.top);
}

</script>

Link to comment
https://forums.phpfreaks.com/topic/53834-firefox-wont-display-it-ie-will/
Share on other sites

kinda tough to read, do you indent? anyway, is currentStyle a js attribute that you can access? and do you have ids starting with numbers?(that wont validate)

 

nah currentStyle is an ie only thing, that's your problem

 

http://www.quirksmode.org/dom/getstyles.html

You can check out the NoGray JavaScript Library, it has a lot of the style functions you want (in the base.js), and you can get any current style in any browser using the getStyle() function

 

http://www.nogray.com

 

The getStyle doesn't work.In the support forums it says i need the IE_loader.js.Where I can find that?

I am sorry about the documentations, just updated the NoGray Library and didn't have time to update the docs.

 

Here is how you can use the getStyle function

 

I remove the IE loader file to speed up the JS library and reduce the number of files you'll need

 

Let's say I want to get the background color of a div tag with the ID "main_div" the code will be like the following

<html>
<head>
<!-- including the base.js from the NoGray JS Library -->
<script language="javascript" src="nogray_lib/base.js" type="text/javascript"></script>

<script language="javascript">
function ini_page(){
	// this function will set all the function of the NoGray library
	// to the object, you can add as many objects as you want
	// make_NoGray(object1[, object2, object3, ...])

	// the _obj function will return the object with the id
	// the same as document.getElementById()

	make_NoGray(_obj('main_div'));

	// the getStyle function will return the current style of the object
	// the style property must be in a valid JavaScript format
	// backgroundColor is good
	// background-color won't work
	// background won't work, must be a full property
	alert (_obj('main_div').getStyle("backgroundColor"));

}
</script>

</head>
<body onload="ini_page();">
<div id="main_div" style="background:#efefef;">Hello World</div>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.