Re: Accessing the DOM for a currently browsed document

Quoting Krzysztof Maczynski <chris___m@hotmail.com>:

> 
> Script fragments like the following one (in ECMAScript) are ubiquitous:
> 
> function setActiveStyleSheet(title) {
>   var i, a, main;
>   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
>     if(a.getAttribute("rel").indexOf("style") != -1 &&
> a.getAttribute("title")) {
>       a.disabled = true;
>       if(a.getAttribute("title") == title) a.disabled = false;
>     }
>   }
> }
> 
> My question is:
> Why is this supposed to work? We all know the intent of the author
> (and practice of browser vendors) that the global variable named
> document has as its value an object of type HTMLDocument
> (i.e. implementing the HTMLDocument interface), representing the
> document currently browsed. That would obviously be a host object,
> as defined in ECMA-262. Is this stated anywhere in the specs that
> such a host object should be provided? The right place for this would be
>
http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/ecma-script-binding.html
> (or some other binding appendix; if I recall correctly, the HTML DOM
> pertains only to HTML documents served as text/html). Nevertheless,
> having searched some binding appendices, it seems to me that the
> only host object for ECMAScript defined by DOM is
> DOMImplementationRegistry (the value is an object implementing
> an interface of the same name). What a standards-based browser
> should do when executing the above code is to complain that null
> (which is the value of document) doesn't implement a method called
> getElementsByTagName. And thus almost all "standards-based"
> scripting examples are in fact based also on this vendor-agreed
> host object. Am I right?
> 
> Thanks for your replies,
> 
> Chris
> 

If I get your point right, I disagree with you. As ECMA-262 states the
window.document object is a host object indeed, since it is not native
nor build-in.

Nowhere is stated that the global object the window object is. The only
document that states it is the ECMA-262 standard:

"for example, in the HTML document object model the window property of the 
global object is the global object itself" [1]

Nor is stated anywhere the window.document property implements the
HTMLDocument interface.

Stating a HTMLDocument object is needed (on the global object), does not 
tell how the window.document property should implement the HTMLDocument 
interface.

Current browser vendors have agreed that the window.document object
implements the HTMLDocument interface. To my mind it is as clear as can be.
It is not stated explicitely, but if you read all the examples in the diffent
specs, you'd agree this is how it is supposed to work.

I am totally new to this stuff, so maybe I am completely wrong.

-jorgen

[1] 10.1.5 Global Object. (1999). 
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

Received on Friday, 7 October 2005 12:06:18 UTC