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

Javascript in netscap

P: n/a
Hello friends, pls tell me why this script not working in my netscap7.1
onload function is (document.layers)

function load(){
if(document.all) alert("ie");
if(document.layers) alert("ns");
}
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Mayur" <ma********@indiatimes.com> wrote in message
news:ba**************************@posting.google.c om...
Hello friends, pls tell me why this script not working in my netscap7.1 onload function is (document.layers)

function load(){
if(document.all) alert("ie");
if(document.layers) alert("ns");
}


document.layers is not supported in that browser, use
document.getElementById instead

Please read http://jibbering.com/faq/#FAQ4_26
--
Andrew Urquhart
- FAQ: http://jibbering.com/faq
- Archive: http://groups.google.com/groups?grou...ang.javascript
- Reply: http://www.andrewu.co.uk/about/conta...ject=Re%3A+clj
Jul 20 '05 #2

P: n/a
On 1 Mar 2004 05:39:38 -0800, Mayur <ma********@indiatimes.com> wrote:
Hello friends, pls tell me why this script not working in my netscap7.1
Knowing what you are trying to acheive might help.
onload function is (document.layers)
(document.layers) is not a function. A more explicit example would be good.
function load(){
if(document.all) alert("ie");
Support for document.all does not indicate Internet Explorer. Opera, and
no doubt other browsers, support the collection.
if(document.layers) alert("ns");
Support for document.layers does not indicate Netscape. Netscape 7 will
evaluate the expression, typeof document.layers, to undefined.
}


Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3

P: n/a


function load(){
if(document.all) alert("ie");
if(document.layers) alert("ns");
}

thanks for reply.

I have 5 div in my page and I want to identify all as array
(document.layers)
and want to do something on it.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #4

P: n/a
Mayur Vyas wrote:

function load(){
if(document.all) alert("ie");
if(document.layers) alert("ns");
}

thanks for reply.

I have 5 div in my page and I want to identify all as array
(document.layers)
and want to do something on it.


Did you bother reading the FAQ that was linked to?

Netscape 7 does *not* support document.layers nor does it support
document.all

And on top of that, your test is utterly useless at identifying ie and
ns, as there are a lot more browsers that support document.all than ie
and more browsers that support document.layers than ns. There is even a
browser that supports *both* of them so you would get both alerts. And
not all versions of NS (6 and 7) support document.layers, they use
document.getElementById as do most modern browsers. (I would say all
modern browsers but as soon as I do someone will come up with one that
doesn't)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 20 '05 #5

P: n/a
On 02 Mar 2004 04:58:18 GMT, Mayur Vyas <ma*******@yahoo.com> wrote:
I have 5 div in my page and I want to identify all as array
(document.layers)
and want to do something on it.

You can't - did you miss where you were told that already?
"Documenrt.all" is a Microsoft extension (that happens to be managed
by a lot more than MSIE - so is no good at all as a browser test)
whereas "document.layers" is an EARLY Netscape extension that works on
more than just Netscape (but doesn't work on modern Netscape).

You really, really do have to use "document.GetElementById ("id") - as
you were told earlier/
Jul 20 '05 #6

P: n/a
Mayur Vyas wrote:
[...]
I have 5 div in my page and I want to identify all as array
(document.layers) and want to do something on it.


With proper quoting[1], you could have noticed that there is no
"document.layers" object in the Gecko DOM. You can, however,
use a method of the W3C DOM to refer to the collection of
"HTMLDivElement" objects:

document.getElementsByTagName("div")

Similar to an Array object, an HTMLCollection object allows to
access its elements through their zero-based index as properties
of the object. Unlike an Array object, it also allows to access
its elements through the name and/or ID of the element object,
if set.

Note that the above method is not supported in all
DOMs, so you should test for it before using it:
<http://pointedears.de.vu/scripts/test/whatami>
PointedEars
___________
[1] <http://www.netmeister.org/news/learn2quote.html>
Jul 23 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.