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

What Dom Objects can I expect to see in JS global scope?

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've just started programming JS, and one question keeps nagging me:

I can insert a <script> element anywhere in HTML, and when it's
executed some DOM objects are created, and placed in the global scope of
the script object.

But which ones are placed in the global scope?

The only one I know of for certain is the "document" object.

I have a feeling that I've seen references to the parent of the <script>
element inserting it's properties and methods into the global scope, but
cannot confirm this.

Also, of particular interest is what goes into the global scope in the
following 2 conditions:

events of form:
<element onload = "jsOnloadFunction()"/>

In this case www.quiksmode.org says the object "this" is
available, and refers to the element the script is invoked on.
What else is placed in the global context?

links of form "javascript:jsFunction()"
I have no idea what goes into the global scope in this case!!

Direct answers, and pointers to information welcome

Bye
-Rob.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFB4sHA2vfwxdLxwWYRAlGlAJ9EKtHvDUuPNriV1I0rzN ZPJ9sZ1QCfcXno
/THPf0dX2dTOTMa/sdu5EYE=
=7fin
-----END PGP SIGNATURE-----
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


Robert North wrote:

I can insert a <script> element anywhere in HTML, and when it's
executed some DOM objects are created, and placed in the global scope of
the script object.


I am not sure what you refer to with 'script object' and 'global scope'
of the script object but in JavaScript/ECMAScript there is a so called
global object on which global variables are created as properties and in
client-side JavaScript the global object is usually the window object.

Which properties the global object has when HTML is parsed depends on
the browser, MSIE makes any element with an id attribute a property of
the window object (which is the global object) that is if you have
<div id="div1">...</div>
then the property
window.div1
is a reference to that div element object. I think that happens in IE
even for elements taking a name attribute (e.g. <form>, <img>).

Opera 7 I think tries to follow the IE behaviour, Opera 6 as far as I
remember followed the IE behaviour only when the browser user set the
browser to identify as IE.

In general you should not rely on the browser making elements available
as properties of the window object but you should use the W3C DOM
methods like document.getElementById.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.