Why does Document.prototype.getElementsByName exist in Chrome?

不想你离开。 提交于 2019-12-23 12:17:34

问题


As I know,getElementsByName is a function defined in HTMLDocument,and HTMLDocument inherits from Document,and Document inherits from Node.

So why I can see Document.prototype.getElementsByName in Chrome but not Firefox?Does not Chrome implement DOM2 spec?


回答1:


Does not Chrome implement DOM2 spec?

Yeah, probably not. I'd guess they at least implement DOM 3, if not a more current version :-)

However, those don't define a getElementsByName either. So how did they get this? It is actually specified in HTML5 (WHATWG/W3) on the Document partial interface:

The DOM specification defines a Document interface, which this [HTML5] specification extends significantly […]

And at http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom I found the note

Because the HTMLDocument interface is now obtained using binding-specific casting methods instead of simply being the primary interface of the document object, it is no longer defined as inheriting from Document.

So the specification details of these interfaces are still in progress, and varying. Notice that browsers are not even supposed to export any kind of DocumentPrototype - the specs do only define interfaces, not the exact EcmaScript binding representation of them. WebIDL does.

So Chrome does follow the newer specs (but still has some HTMLDocument?), while Firefox implements an older version. However, it only really matters that these methods do exist on every window.document - not how they got there :-)



来源:https://stackoverflow.com/questions/21771768/why-does-document-prototype-getelementsbyname-exist-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!