Browser support for getElementsByTagNameNS

谁都会走 提交于 2020-01-03 18:15:11

问题


Which browsers/versions support getElementsByTagNameNS(), and to which extent? I can't seem to find a good reference.

[Edit] I am interested in a complete reference, but my immediate need is for namespaced xml returned from an AJAX call (which jQuery doesn't seem to handle btw).


回答1:


Sitepoint says Firefox as of version 1.5, Safari as of version 3 and Opera as of version 9.

Firefox versions lower than 3.6 did a case insensitive search which as corrected in version 3.6.

Microsoft claims to support it as of IE9. However, according to Dottoro, this is only true for HTML documents. I'm not sure if you can't really trust Dottoro because selecting by namespace does not make sense for HTML documents anyway. You should be able to use XPath if getElementsByTagNameNS is not supported. Wrappers are required, though, since IE does not support the standard API – see Yaldex and NCZOnline for hints how to get IE to cooperate. Or ask Microsoft's support.

I would recommend to ensure XHTML documents have actually been served with a XML content type when you plan to use the function on the DOM of a web page.

Chromium 14 does also support the method (and honors namespaces in contrast to old Safari versions). Support might have been in long before, I just don't know the earliest Chrome/Chromium version with support.

It seems all browsers but not IE are supporting DOM Level 3 XPath. Use XPath to replace calls to getElementsByTagNameNS if there are issues with it. See NCZOnline for an introduction and notes on browser support.




回答2:


I know this is old, but this might be useful to someone. You can just use plain old getElementsByTagName in IE. Instead of calling node.getElementsByTagNameNS('someNamespace', 'someNodeName'), call node.getElementsByTagName('someNamespace:someNodeName').

Or use the following shim:

var getElementsByTagNameNS = function(node, ns, tagName) {
  if (node.getElementsByTagNameNS) {
      return node.getElementsByTagNameNS(ns, tagName);
  }

  return node.getElementsByTagName(ns + ':' + tagName);
};

And call it like this:

getElementsByTagNameNS(someNode, 'someNamespace', 'someNodeName');



回答3:


Have you taken a look at this reference?

Specifically, here.



来源:https://stackoverflow.com/questions/8378470/browser-support-for-getelementsbytagnamens

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