Jump to content

window.document.all ?


toiditimtoi992

Recommended Posts

They are legacy (i.e. old, and superseded) properties of the document object. The all property stores an array of all elements in the document, indexed by ID, while the layers property stores an array of all <layer> (a proprietary Netscape tag) elements.Nowadays, it is preferable to use document.getElementById() and document.getElementsByTagName().

Link to comment
Share on other sites

You will see those properties in old scripts and tutorials. They were often used to identify which browser the user was running (browser sniffing), and then parts of the application would fork into code for Explorer or code for Netscape. One problem with the technique is that document.layers no longer exists. So it is a bad test.Another problem is that the differences between Explorer and standards-compliant browsers has narrowed and is getting narrower. A reason for learning if a browser was Explorer was to avoid properties and methods not supported by Explorer. But new versions of Explorer do support a lot of those properties and methods, and it is usually better to use them if they are available. If you are not sure, because IE8-9 supports something IE6-7 does not, then code should test for the property or method in question. Example:

if (window.getSelection) {// this method is available, so use it}else if (document.selection) {// this older property exists, so use it instead}

Code like that does not depend on the name or version of the browser; it depends on the existence of the property/method and will not become obsolete with time.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...