W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2005

Accessing the DOM for a currently browsed document

From: Krzysztof Maczynski <chris___m@hotmail.com>
Date: Thu, 6 Oct 2005 16:26:42 +0200
Message-ID: <BAY17-DAV10B6B990FCD33E505CC5069E850@phx.gbl>
To: <www-dom@w3.org>

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
Received on Thursday, 6 October 2005 14:26:43 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:58 GMT