mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Remove script tags from cloned DOM
This commit is contained in:
parent
15ca3381eb
commit
84c1dc6283
17
src/core.js
17
src/core.js
@ -86,10 +86,25 @@ function createWindowClone(ownerDocument, width, height, options) {
|
||||
documentClone.write("<!DOCTYPE html>");
|
||||
documentClone.close();
|
||||
|
||||
documentClone.replaceChild(documentClone.adoptNode(documentElement), documentClone.documentElement);
|
||||
documentClone.replaceChild(removeScriptNodes(documentClone.adoptNode(documentElement)), documentClone.documentElement);
|
||||
if (options.type === "view") {
|
||||
container.contentWindow.scrollTo(window.scrollX, window.scrollY);
|
||||
}
|
||||
resolve(container);
|
||||
});
|
||||
}
|
||||
|
||||
function removeScriptNodes(parent) {
|
||||
[].slice.call(parent.childNodes, 0).filter(isElementNode).forEach(function(node) {
|
||||
if (node.tagName === "SCRIPT") {
|
||||
parent.removeChild(node);
|
||||
} else {
|
||||
removeScriptNodes(node);
|
||||
}
|
||||
});
|
||||
return parent;
|
||||
}
|
||||
|
||||
function isElementNode(node) {
|
||||
return node.nodeType === Node.ELEMENT_NODE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user