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:
parent
ea6062c85b
commit
ae019f174c
28
src/Clone.js
28
src/Clone.js
@ -614,7 +614,7 @@ export const cloneWindow = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
documentClone.open();
|
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???
|
// Chrome scrolls the parent document for some reason after the write to the cloned window???
|
||||||
restoreOwnerScroll(referenceElement.ownerDocument, scrollX, scrollY);
|
restoreOwnerScroll(referenceElement.ownerDocument, scrollX, scrollY);
|
||||||
documentClone.replaceChild(
|
documentClone.replaceChild(
|
||||||
@ -626,3 +626,29 @@ export const cloneWindow = (
|
|||||||
return iframeLoad;
|
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;
|
||||||
|
};
|
||||||
|
11
tests/reftests/images/doctype.html
Normal file
11
tests/reftests/images/doctype.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script type="text/javascript" src="../../test.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<img src="../../assets/image.jpg" />
|
||||||
|
<img src="../../assets/image2.jpg" style="display:block;" />
|
||||||
|
<br>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user