mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Use correct doctype in cloned Document (Fix #1298)
This commit is contained in:
28
src/Clone.js
28
src/Clone.js
@ -614,7 +614,7 @@ export const cloneWindow = (
|
||||
});
|
||||
|
||||
documentClone.open();
|
||||
documentClone.write('<!DOCTYPE html><html></html>');
|
||||
documentClone.write(`${serializeDoctype(document.doctype)}<html></html>`);
|
||||
// Chrome scrolls the parent document for some reason after the write to the cloned window???
|
||||
restoreOwnerScroll(referenceElement.ownerDocument, scrollX, scrollY);
|
||||
documentClone.replaceChild(
|
||||
@ -626,3 +626,29 @@ export const cloneWindow = (
|
||||
return iframeLoad;
|
||||
});
|
||||
};
|
||||
|
||||
const serializeDoctype = (doctype: ?DocumentType): string => {
|
||||
let str = '';
|
||||
if (doctype) {
|
||||
str += '<!DOCTYPE ';
|
||||
if (doctype.name) {
|
||||
str += doctype.name;
|
||||
}
|
||||
|
||||
if (doctype.internalSubset) {
|
||||
str += doctype.internalSubset;
|
||||
}
|
||||
|
||||
if (doctype.publicId) {
|
||||
str += `"${doctype.publicId}"`;
|
||||
}
|
||||
|
||||
if (doctype.systemId) {
|
||||
str += `"${doctype.systemId}"`;
|
||||
}
|
||||
|
||||
str += '>';
|
||||
}
|
||||
|
||||
return str;
|
||||
};
|
||||
|
Reference in New Issue
Block a user