- From: Simon Pieters <simonp@opera.com>
- Date: Wed, 25 Jul 2007 10:47:46 +0200
- To: public-html <public-html@w3.org>
(This is part of my detailed review of the Document Object Model section.) document.dir is said to reflect the dir content attribute on "the html element". http://www.whatwg.org/specs/web-apps/current-work/#dir1 Some tests to figure out what IE does: http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElement%28%22body%22%29%3B%0D%0Adocument.insertBefore%28e%2C%20document.documentElement%29%3B%0D%0Ae.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E (this one will probably hang IE7 if you do something) http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElement%28%22foo%22%29%3B%0D%0Adocument.insertBefore%28e%2C%20document.documentElement%29%3B%0D%0Ae.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElement%28%22body%22%29%3B%0D%0Adocument.insertBefore%28e%2C%20document.documentElement%29%3B%0D%0Avar%20ee%20%3D%20document.createElement%28%22bar%22%29%3B%0D%0Ae.appendChild%28ee%29%3B%0D%0Aee.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E (also hangs IE7 after doing something) Also try the same but with "frameset" instead of "body"... In IE7, "the html element" is the first html element that doesn't have a body or frameset element ancestor. (IE won't let me replace or delete the last "html" element in the DOM so there will always be at least one present.) For Opera: http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElement%28%22body%22%29%3B%0D%0Adocument.replaceChild%28e%2C%20document.documentElement%29%3B%0D%0Ae.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElement%28%22foo%22%29%3B%0D%0Adocument.replaceChild%28e%2C%20document.documentElement%29%3B%0D%0Ae.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElement%28%22body%22%29%3B%0D%0Adocument.replaceChild%28e%2C%20document.documentElement%29%3B%0D%0Avar%20ee%20%3D%20document.createElement%28%22bar%22%29%3B%0D%0Ae.appendChild%28ee%29%3B%0D%0Aee.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElementNS%28%22http%3A//www.w3.org/1999/xhtml%22%2C%22foo%22%29%3B%0D%0Adocument.replaceChild%28e%2C%20document.documentElement%29%3B%0D%0Avar%20ee%20%3D%20document.createElement%28%22bar%22%29%3B%0D%0Ae.appendChild%28ee%29%3B%0D%0Aee.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%0D%0A%3Cscript%3E%0D%0Avar%20e%20%3D%20document.createElementNS%28%22http%3A//www.example.org/foo%22%2C%22foo%22%29%3B%0D%0Adocument.replaceChild%28e%2C%20document.documentElement%29%3B%0D%0Avar%20ee%20%3D%20document.createElement%28%22bar%22%29%3B%0D%0Ae.appendChild%28ee%29%3B%0D%0Aee.appendChild%28document.createElement%28%22html%22%29%29%3B%0D%0Adocument.dir%3D%22ltr%22%3B%0D%0A%3C/script%3E In Opera, document.dir reflects the dir attribute on the root element, unless the root element is a non-HTML element. (Opera won't let me remove the last element in the DOM so there will always be at least one root element present.) For Firefox and Safari: http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C%21DOCTYPE%20html%3E%3Cscript%3Edocument.dir%3D%22rtl%22%3Bw%28document.dir%29%3C/script%3Etest http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%3Chtml%20dir%3Drtl%3E%3Cscript%3Edocument.dir%3D%22ltr%22%3Bw(document.dir)%3C/script%3Etest In Firefox, document.dir doesn't reflect any content attribute, but it does affect rendering. Getting document.dir returns the Document's direction. In Safari, setting document.dir doesn't do anything and getting always returns the empty string. Now, I suggest that the definition of "the html element" be changed to match what IE does, i.e.: The html element of a document is the first html element that doesn't have a body or frameset element ancestor, if there is one, or null otherwise. -- Simon Pieters Opera Software
Received on Wednesday, 25 July 2007 08:47:50 UTC