JS:dom-to-image网页截图保存
【摘要】 文档:https://github.com/tsayen/dom-to-image
CDN
<script src="https://cdn.bootcdn.net/ajax/libs/dom-to-image/2.6.0/dom-to-image.js"></script>
1
代码示例
<html lang="en">
...
文档:https://github.com/tsayen/dom-to-image
CDN
<script src="https://cdn.bootcdn.net/ajax/libs/dom-to-image/2.6.0/dom-to-image.js"></script>
代码示例
<html lang="en">
<head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> table { width: 200px; border-collapse: collapse; border: 1px solid black; } tr { background: green; } </style> <script src="https://cdn.bootcdn.net/ajax/libs/dom-to-image/2.6.0/dom-to-image.js"></script>
</head>
<body> <input type="button" onclick="saveImage()" value="保存图片" /> <table id="table"> <tr> <td rowspan="3">200</td> <td>200</td> <td>300</td> </tr> <tr> <td rowspan="2">500</td> <td>600</td> </tr> <tr> <td>600</td> </tr> </table> <script> function saveImage() { domtoimage .toPng(document.getElementById("table")) .then(function (dataUrl) { var link = document.createElement("a"); link.download = "my-image-name.jpeg"; link.href = dataUrl; link.click(); }); } </script>
</body>
</html>
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/111606168
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)