By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

css layer not working in Firefox or Netscape

P: n/a
Hi Javascript gurus:

I have tried several things, using several Javascript books, but can't get
this to work in Netscape (latest version) and Firefox (latest v.). It works
in MIE and Opera fine. A box (defined by a css layer) is supposed to pop
out to the right when the corresponding box on the far left is moused over.
The first function defines a layer id to the next function which pops out
the box. After debugging in Venkman, it looks like the first function
cannot define the layer id properly to the second function, which actually
slides the box (layer) to the right.

I thought that the getElementById function was supposed to work for Firefox,
but I must be using it wrong(???)

To see how it's supposed to work, view the following page in MIE or Opera:
http://www.tfn.net/~chorale/join_us.html

function makeName(layerID) {

if (document.all)
{ refname = eval("document.all." + layerID + ".style") }
else if (document.layers)
{ refname = eval("document.layers(layerID)"); }
else
{ refname = document.getElementById("layerID"); }
// { refname = layerID }
// { refname = eval("document." + layerID) }
// { refname = eval("document." + layerID) }
// { refname = layerID; }
return refname;
}

function slide () {
if ((parseInt(layername.left) < xgoal) ||
(parseInt(layername.top) < ygoal))
{ layername.left = parseInt(layername.left) + xhop;
layername.top = parseInt(layername.top) + yhop;
// window.setTimeout("slide()", delay)
}
else if ((parseInt(layername.left) == xgoal) ||
(parseInt(layername.top) == ygoal))
{ layername.left = parseInt(layername.left) - xhop;
layername.top = parseInt(layername.top) - yhop;
// window.setTimeout("slide()", delay)
}
}

This is a portion of the HTML code that calls the box (in this case, the
"sponsors" css class), and assigns it a layer name, which is then passed to
the slide function, which moves the box to the right based on the x & y
coordinates. The box is defined by a css <div class=> statement as
'sponsors'.:

layername=makeName('sponsors'); yhop=0; ygoal=150; xhop=165; xgoal=165;
slide()";

Thanks for any help you can give.
--
Rebecca Levings
Lively Health Products
850-443-4641
rl**********@comcast.net
http://www.lively.myarbonne.com
https://www.juiceplus.com/athlete/+rl21248
Nov 26 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


You are leaving out .style as part of the object assignment in the
..layers and .getElementById lines for "refname":

if (document.all)
{ refname = eval("document.all." + layerID + ".style") }
else if (document.layers)
here ^
{ refname = eval("document.layers(layerID)"); }
here^
else
{ refname = document.getElementById("layerID"); }
and here^

chances are IE is using the .all part, since is in met in the IF and
skipping the rest, thus it works, Opera does .all object too, so,
Geckos do .all too but limited.
Danny
Nov 26 '05 #2

P: n/a
jsreblev wrote:
if (document.all)
Needed exclusively for Internet Explorer 4. Other versions of Internet
Explorer support it. Some other browsers support it, but, AFAIK they all
return false if you test for it (on the principle that if you are smart
enough to test for it, your smart enough to use the standard DOM).
else if (document.layers)
Needed for, and supported only by, Netscape 4.x.
{ layername.left = parseInt(layername.left) + xhop;


http://www.mozilla.org/docs/web-deve...ade_2.html#dom

Not going near the style property of the element, and failing to set units
(which are required for non-zero lengths).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Nov 26 '05 #3

P: n/a
jsreblev wrote:
[...]
function makeName(layerID) {

if (document.all)
{ refname = eval("document.all." + layerID + ".style") }


What Daivd said, plus the use of eval here is totally redundant:

refname = document.all.layerID.style;

There is also no need to make refname global (it's not needed at all).
Test getElementById first, it will suit 99% of browsers:

if (document.getElementById) {
return document.getElementById(layerID).style;
} else if (document.all)
return document.all[layerID].style;
} else if (document.layers){
return document.layers(layerID);
}
return null;
Untested, based on your code.

[...]

--
Rob
Nov 26 '05 #4

P: n/a
On 2005-11-25, jsreblev <js*******@comcast.net> wrote:
Hi Javascript gurus:

I have tried several things, using several Javascript books, but can't get
this to work in Netscape (latest version) and Firefox (latest v.). It works
in MIE and Opera fine. A box (defined by a css layer) is supposed to pop
out to the right when the corresponding box on the far left is moused over.
The first function defines a layer id to the next function which pops out
the box. After debugging in Venkman, it looks like the first function
cannot define the layer id properly to the second function, which actually
slides the box (layer) to the right.

I thought that the getElementById function was supposed to work for Firefox,
but I must be using it wrong(???)

To see how it's supposed to work, view the following page in MIE or Opera:
http://www.tfn.net/~chorale/join_us.html

function makeName(layerID) {

if (document.all)
{ refname = eval("document.all." + layerID + ".style") }
else if (document.layers)
{ refname = eval("document.layers(layerID)"); }


is document.layers a function or a object?

also I don't see the element you are trying to access, does it have the id
property?

--

Bye.
Jasen
Nov 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.