可以使用 HTML5 Canvas 截取页面的屏幕截图吗?
htmljavascriptprogramming scripts更新于 2025/3/13 13:00:17
Html2Canvas 是一个 JavaScript 库,可以截取整个网页或特定部分的屏幕截图。它不会截取屏幕截图,而是根据页面信息创建视图。
示例
下面给出了一个示例代码。这里,html2canvas.js 脚本包含在<head>中。调用 html2canvas() 方法。返回 base64 值,最终创建图像源或图像文件。
<!DOCTYPE html>
<html>
<head>
<script src="html2canvas-master/dist/html2canvas.js"></script>
</head>
<body>
<h1>Take screenshot</h1>
<div class="container" id='container' >
<imgsrc='images/one.jpg' width='50' height='50'>
<imgsrc='images/two.jpg' width='50' height='50'>
</div>
<input type='button' id='but_screenshot' value='Take screenshot' onclick='screenshot();'><br/>
<script>
function screenshot(){
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
}
</script>
</body>
</html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

