Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: WrongDocumentError #3

Closed
Aqours opened this issue Dec 26, 2017 · 0 comments
Closed

Error: WrongDocumentError #3

Aqours opened this issue Dec 26, 2017 · 0 comments

Comments

@Aqours
Copy link
Owner

Aqours commented Dec 26, 2017

这个错误通常是在当前文档(Document)插入其他文档的节点(Node)会产生的错误,常见于IE。

通常来说不同的文档间的节点不能相互插入,通常需要导入节点再插入到文档中,现代浏览器智能化了这个过程,导入操作由浏览器自身完成了。但并不是所有浏览器都是这么做的,因此先导入后插入是更为稳妥的做法。

var body = document.body; // current context
var htmlString = '<div><span>123</span></div>';
var doc = new DOMParser().parseFromString(htmlString, 'text/html'); // other context

console.log(body.ownerDocument === doc); // false

// Mordern Browser (Not Recommend)
// body.appendChild(doc.body.firstChild);

var otherContextNode = doc.body.firstChild;
var currentContextNode = document.importNode(otherContextNode, true);
body.appendChild(currentContextNode);
@Aqours Aqours self-assigned this Dec 26, 2017
@Aqours Aqours closed this as completed Feb 4, 2018
@Aqours Aqours reopened this Jun 19, 2018
@Aqours Aqours closed this as completed Jun 22, 2018
@Aqours Aqours reopened this Jan 15, 2019
@Aqours Aqours closed this as completed Jan 25, 2019
@lock lock bot added the Unattended label Jun 14, 2019
@lock lock bot locked and limited conversation to collaborators Jun 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant