Use correct doctype in cloned Document (Fix #1298)

This commit is contained in:
MoyuScript
2018-01-02 19:46:46 +08:00
parent ca2200d270
commit b12f9fef0d
2 changed files with 38 additions and 1 deletions

View File

@ -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;
};