javascript DOM 异常:HIERARCHY_REQUEST_ERR (3) 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13343839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 18:30:08  来源:igfitidea点击:

DOM Exception: HIERARCHY_REQUEST_ERR (3) error

javascriptjqueryinternet-explorer-9domexception

提问by PeterLin

The following code works fine in chrome and Firefox, but breaks in IE 9.0.

以下代码在 chrome 和 Firefox 中运行良好,但在 IE 9.0 中会中断。

message.nodeTree.childNodes[1].childNodes[0].childNodes[0].appendChild(pkf_util.createXmlTextNode(text));

message.nodeTree.childNodes[1].childNodes[0].childNodes[0].appendChild(pkf_util.createXmlTextNode(text));

when I try to input something via textarea,it comes with SCRIPT5022:

当我尝试通过 textarea 输入内容时,它带有 SCRIPT5022:

DOM Exception: HIERARCHY_REQUEST_ERR (3) line 481 character 29;

DOM 异常:HIERARCHY_REQUEST_ERR (3) line 481 character 29;

Any ideas why it's not working in IE 9.0?

任何想法为什么它不能在 IE 9.0 中工作?

回答by epeleg

I know its a long time since the Q was asked but I reached it based on the error message. specifically in my case I was getting the following error: "HIERARCHY_REQUEST_ERR: DOM Exception 3: A Node was inserted somewhere it doesn't belong.".

我知道自问 Q 以来已经很长时间了,但我根据错误消息到达了它。特别是在我的情况下,我收到以下错误:“HIERARCHY_REQUEST_ERR:DOM 异常 3:一个节点被插入到它不属于的地方。”。

I was trying to append a node that I was creating using jquery to some other node in my html document. It turned out that by mistake I used $('div')instead of $('<div>')for the creating the new (appended) node.

我试图将我使用 jquery 创建的节点附加到我的 html 文档中的其他节点。事实证明,我错误地使用$('div')而不是$('<div>')用于创建新(附加)节点。

I hope this will help someone in the future.

我希望这会在将来对某人有所帮助。

回答by undess

This can be a solution...

这可以是一个解决方案......

var element = document.createElement('iframe');
element.src = url;
document.getElementsByTagName('body')[0].appendChild(element);    

Good luck

祝你好运

回答by John Dvorak

DOM exception 3means you've tried to insert an element to a place in the DOM where it doesn't belong. (ref.)

DOM exception 3意味着您已尝试将元素插入 DOM 中不属于它的位置。(参考

Possible causes:

可能的原因:

  • IE9 doesn't consider the XML node created by the library a valid DOM node.
  • The node created is a valid DOM node but it's being appended somewhere it doesn't belong (such as anything being appended to a node that's supposed to be a leaf)
  • The node created is not actually a new element, but rather a parent of the node being appended to. This would classify as a bug in the library.
  • If you try to append a nullanywhere, you're practically asking for a DOM exception. Perhaps your library fails on IE9?
  • IE9 不认为库创建的 XML 节点是有效的 DOM 节点。
  • 创建的节点是一个有效的 DOM 节点,但它被附加到它不属于的地方(例如任何被附加到应该是叶子的节点)
  • 创建的节点实际上不是一个新元素,而是被附加到的节点的父节点。这将归类为库中的错误。
  • 如果您尝试在null任何地方附加 a ,您实际上是在请求 DOM 异常。也许你的图书馆在 IE9 上失败了?

Google search on pkf_utilreturns ... this question, so we cannot rule out a bug in pkf_util.

谷歌搜索pkf_util返回......这个问题,所以我们不能排除pkf_util.