mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Correctly clone dynami CSSStyleSheets (Fix #1370)
This commit is contained in:
parent
8788a9f458
commit
4c14894a0a
@ -229,6 +229,15 @@ export class DocumentCloner {
|
||||
return tempIframe;
|
||||
}
|
||||
|
||||
if (node instanceof HTMLStyleElement && node.sheet && node.sheet.cssRules) {
|
||||
const css = [].slice
|
||||
.call(node.sheet.cssRules, 0)
|
||||
.reduce((css, rule) => css + rule.cssText, '');
|
||||
const style = node.cloneNode(false);
|
||||
style.textContent = css;
|
||||
return style;
|
||||
}
|
||||
|
||||
return node.cloneNode(false);
|
||||
}
|
||||
|
||||
|
37
tests/reftests/dynamicstyle.html
Normal file
37
tests/reftests/dynamicstyle.html
Normal file
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Dynamic style</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<script type="text/javascript" src="../test.js"></script>
|
||||
<style id="style">
|
||||
@font-face {
|
||||
font-family: 'Roboto';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Roboto'), local('Roboto-Regular'), url(https://fonts.gstatic.com/s/roboto/v18/CWB0XYA8bzo0kSThX0UTuA.woff2) format('woff2');
|
||||
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2212, U+2215;
|
||||
}
|
||||
body { font-family: "Roboto", serif }
|
||||
|
||||
div {
|
||||
padding: 20px;
|
||||
}
|
||||
.div1 {
|
||||
background: darkgreen;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
document.querySelector('#style').sheet.insertRule(
|
||||
'.div2 { background: darkgreen; color:white; }',
|
||||
document.querySelector('#style').sheet.cssRules.length
|
||||
);
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="div1">Static styles</div>
|
||||
<div class="div2">Dynamic styles</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user