JS not working in Forefox

T

Trevor L.

I have some JS code which I obtained from a website.

Its purpose is to load one division("wait") which is just a WAIT message
while images are being loaded and then, on completion, show another division
("mainpage") with all images loaded.

This is the function called after loading:

function showPage()
{
if(document.all)
{
document.all["wait"].style.visibility="hidden";
document.all["mainpage"].style.visibility="visible"; }
else if(document.layers)
{
document.layers["wait"].visibility="hidden";
document.layers["mainpage"].visibility="visible"; }
}

It works fine in IE but not in Firefox.
I can't see why not.
--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html
 
J

Joe Fawcett

Trevor L. said:
I have some JS code which I obtained from a website.

Its purpose is to load one division("wait") which is just a WAIT message while
images are being loaded and then, on completion, show another division
("mainpage") with all images loaded.

This is the function called after loading:

function showPage()
{
if(document.all)
{
document.all["wait"].style.visibility="hidden";
document.all["mainpage"].style.visibility="visible"; }
else if(document.layers)
{
document.layers["wait"].visibility="hidden";
document.layers["mainpage"].visibility="visible"; }
}

It works fine in IE but not in Firefox.
I can't see why not.
I've never used Firefox but that code looks quite old, I'd be surprised if it
supported either document.all or document.layers. Try this as a quick fix:
function showPage()
{
if(document.all)
{
document.all["wait"].style.visibility="hidden";
document.all["mainpage"].style.visibility="visible"; }
else if(document.layers)
{
document.layers["wait"].visibility="hidden";
document.layers["mainpage"].visibility="visible"; }
}
else if(document.getElementById)
{
alert("getElementById"); //remove after testing
document.getElementById("wait").style.visibility="hidden";
document.getElementById("mainpage").style.visibility = "visible";
}
}
If you get the alert but it doesn't work you'll have to check the syntax for
hiding elements via css in Mozilla.
 
B

Bob Lehmann

getElementById is supported by all modern browsers >=4, I believe. Depending
on how many of the older browsers you need to support, it should be all you
need.

Bob Lehmann

Joe Fawcett said:
Trevor L. said:
I have some JS code which I obtained from a website.

Its purpose is to load one division("wait") which is just a WAIT message while
images are being loaded and then, on completion, show another division
("mainpage") with all images loaded.

This is the function called after loading:

function showPage()
{
if(document.all)
{
document.all["wait"].style.visibility="hidden";
document.all["mainpage"].style.visibility="visible"; }
else if(document.layers)
{
document.layers["wait"].visibility="hidden";
document.layers["mainpage"].visibility="visible"; }
}

It works fine in IE but not in Firefox.
I can't see why not.
I've never used Firefox but that code looks quite old, I'd be surprised if it
supported either document.all or document.layers. Try this as a quick fix:
function showPage()
{
if(document.all)
{
document.all["wait"].style.visibility="hidden";
document.all["mainpage"].style.visibility="visible"; }
else if(document.layers)
{
document.layers["wait"].visibility="hidden";
document.layers["mainpage"].visibility="visible"; }
}
else if(document.getElementById)
{
alert("getElementById"); //remove after testing
document.getElementById("wait").style.visibility="hidden";
document.getElementById("mainpage").style.visibility = "visible";
}
}
If you get the alert but it doesn't work you'll have to check the syntax for
hiding elements via css in Mozilla.


--

Joe (MVP)

https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5
 
D

Dave Anderson

Bob Lehmann said:
getElementById is supported by all modern browsers >=4, I believe...

More like >= 5. See the "Applies To" section here:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getelementbyid.asp


Of course, I think getElementById support is required to even call a browser
"modern".



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
T

Trevor L.

Thank you all

I found that this worked in Firefox

function showPage()
{
if(document.all)
{
document.all("wait").style.visibility="hidden"
document.all("mainpage").style.visibility="visible" }
else if(document.getElementById)
{
document.getElementById("wait").style.visibility="hidden"
document.getElementById("mainpage").style.visibility="visible" }
else if(document.layers)
{
document.layers("wait").visibility="hidden"
document.layers("mainpage").visibility="visible" }
}
//------------------------------

The interesting thing is that square brackets do not work in Firefox.

I therefore think that Firefox accepts document.all("wait") but not
document.all["wait"].

For certainty, I guess I should test to see whether Firefox is responding to
document.all or document.getElementById.
Surely Firefox is a modern enough browser to accept both.

As an aside, can anyone tell me when, according to the strict syntax, one
should use square brackets and when round ?

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au




I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html
 
J

Joe Fawcett

Trevor L. said:
Thank you all

I found that this worked in Firefox

function showPage()
{
if(document.all)
{
document.all("wait").style.visibility="hidden"
document.all("mainpage").style.visibility="visible" }
else if(document.getElementById)
{
document.getElementById("wait").style.visibility="hidden"
document.getElementById("mainpage").style.visibility="visible" }
else if(document.layers)
{
document.layers("wait").visibility="hidden"
document.layers("mainpage").visibility="visible" }
}
//------------------------------

The interesting thing is that square brackets do not work in Firefox.

I therefore think that Firefox accepts document.all("wait") but not
document.all["wait"].

For certainty, I guess I should test to see whether Firefox is responding to
document.all or document.getElementById.
Surely Firefox is a modern enough browser to accept both.

As an aside, can anyone tell me when, according to the strict syntax, one
should use square brackets and when round ?
document.all is a collection, the square brackets specify the key of which
element to retrieve. document.getElementById is a method which accepts the id of
the element required, as all methods it uses parentheses.
Had you used my suggestion you'd have seen which one was called.
IE often accepts parentheses when brackets are needed according to the ECMAScipt
specs but I don't think the reverse applies.
 
R

Richard Cornford

Joe said:
Trevor L. wrote:
function showPage()
{
if(document.all)
{
document.all("wait").style.visibility="hidden"
document.all("mainpage").style.visibility="visible" }
else if(document.getElementById)
{
document.getElementById("wait").style.visibility="hidden"
document.getElementById("mainpage").style.visibility="visible" }
else if(document.layers)
{
document.layers("wait").visibility="hidden"
document.layers("mainpage").visibility="visible" }
}
//------------------------------

The interesting thing is that square brackets do not work in Firefox.

I therefore think that Firefox accepts document.all("wait")
but not document.all["wait"].

Actually the reverse is true. The first is a method call, while the
second is a property accessor. Firefox (at least the latest version)
will function with the property accessor, but only to provide
compatibility with badly written 'IE only' web sites.

FireFox is not executing that branch. Well written javascript test for
the existence of browser features before using them, so to avoid
exposing their - document.all - kludge to well written code the test -
if(document.all) - returns false, even though the a - document.all -
collection is implemented.

Modernness has nothing to do with it. document.getElementById - is W3C
Core DOM standard so modern browsers should be expected to implement it.
document.all - is Microsoft proprietary DOM and other browsers implement
it, or not, to provide some compatibility with IE, and sometimes in a
way that only works with property accessor syntaxes rather than method
calls.

Which strict syntax? In ECMAScirpt - document.all['anything'] - is a
bracket notation property accessor (the more flexible alternative to a
dot notation property accessor) and - document.all("anything") - is a
method call with an argument. They are completely different operations;
that they may result in the same value in some environments is entirely
down to the implementation. Remember that in ECMAScript a function is an
object, and may have properties that may be referenced with property
accessors.

document.all is a collection, the square brackets specify
the key of which element to retrieve. document.getElementById
is a method which accepts the id of the element required,
as all methods it uses parentheses. Had you used my
suggestion you'd have seen which one was called. IE often
accepts parentheses when brackets are needed according to
the ECMAScipt specs but I don't think the reverse applies.

It is not so much a matter of accepting parentheses where brackets would
be needed (that would be blowing the language syntax apart), but
providing a collection that can also be called. Approximately the
equivalent of:-

document.all = function(name){
return arguments.callee[name];
};

document.all['anElement'] = document.all[0] = DOM_Element_Ref_1;
document.all['anotherElement'] = document.all[1] = DOM_Element_Ref_2;
// and so on ... (with an assignment to - document.all.length -
// at some point, and maybe the provision of - item - and
// - namedItem - methods for the function object)

var firstEl = document.all['anElement'];
var secondEl = document.all('anotherElement');

// The method call would be expected to be slower due to the
// overheads in entering a new execution context.

With first-class functions in javascript that are also objects, having
an object that can be called also provide public members that can be
referenced with property accessors is completely viable. Indeed,
calling - typeof - on the - document.all - collection in Mac IE 5,
Opera, IceBrowser, and some others, will return "function", exposing how
these collections really work.

Richard.
 
D

Dr John Stockton

JRS: In article <#[email protected]>, dated Sat, 16
Apr 2005 07:32:01, seen in Bob
Lehmann said:
getElementById is supported by all modern browsers >=4, I believe.

Your beliefs are whatever you choose. But I cannot, as an IE4 user,
believe the "=" there.



if (document.all && !document.getElementById) {
document.getElementById = function(id) {
return document.all[id] } }

After that, in a browser without native getElementById but with
document.all - such as MSIE 4 - one can use document.getElementById('Div
').innerHTML = "Hello<br>World" to write to an element called Div ,
etc., etc. It is not an exact full emulation, but generally suffices.

By habit, I prefer to use function DynWrite (see c.l.j FAQ. & via
below).
 
T

Trevor L.

Joe,

I apologise that I didn't use your suggestion. As you can see, I was
confused by the square and round brackets. I do not know the details of how
Javascript works (which is why I asked). I suppose I would know more if I
bought a text on Javascript and studied it, but for a beginner a lot of it
is "suck it and see".

I see a conflict between
1) the purist view (as I see it) of learning everything before using a
language, and
2) easing into it, learning as you go.
In my many years as an IT professional, both approaches have served me well.
In fact, learning by mistakes often enforces the point than a rote sticking
to rules.

I shall read this thread carefully to learn as much as I can from it.
--
May thanks,
Trevor L.
Website: http://tandcl.homemail.com.au

Joe Fawcett said:
Trevor L. said:
Thank you all

I found that this worked in Firefox

function showPage()
{
if(document.all)
{
document.all("wait").style.visibility="hidden"
document.all("mainpage").style.visibility="visible" }
else if(document.getElementById)
{
document.getElementById("wait").style.visibility="hidden"
document.getElementById("mainpage").style.visibility="visible" }
else if(document.layers)
{
document.layers("wait").visibility="hidden"
document.layers("mainpage").visibility="visible" }
}
//------------------------------

The interesting thing is that square brackets do not work in Firefox.

I therefore think that Firefox accepts document.all("wait") but not
document.all["wait"].

For certainty, I guess I should test to see whether Firefox is responding
to document.all or document.getElementById.
Surely Firefox is a modern enough browser to accept both.

As an aside, can anyone tell me when, according to the strict syntax, one
should use square brackets and when round ?
document.all is a collection, the square brackets specify the key of which
element to retrieve. document.getElementById is a method which accepts the
id of the element required, as all methods it uses parentheses.
Had you used my suggestion you'd have seen which one was called.
IE often accepts parentheses when brackets are needed according to the
ECMAScipt specs but I don't think the reverse applies.

--

Joe (MVP)

https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5


I choose Polesoft Lockspam to fight spam, and you?
http://www.polesoft.com/refer.html
 

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

Similar Threads

Browser Sniffers 4
Printing Error 3
Comment not read in Firefox 3
Embedding Video 2
Image Toolbar 2
Centering images 13
Clearing Cache ? 4
Timing Out of an animated GIF 4

Top