是否可以使用javascript获取html文档的图像。我正在寻找像document.getThumbnail()
或window.render()
这样的javascript函数,它返回html文档的PNG
。
答案 0 :(得分:1)
我可以推荐三种不同的API:
Page.captureScreenshot
。 (docs)和example code chrome.desktopCapture
或visibleCapture API。 (docs)和example code 此脚本允许您直接在用户浏览器上截取网页或部分网页的“屏幕截图”。屏幕截图基于DOM,因此它可能不是真实表示的100%准确,因为它不会制作实际的屏幕截图,而是根据页面上可用的信息构建屏幕截图。
答案 1 :(得分:0)
<html>
<head>
<script src="https://code.jquery.com/jquery-3.2.1.slim.js" integrity="sha256-tA8y0XqiwnpwmOIl3SGAcFl2RvxHjA8qp0+1uCGmRmg="
crossorigin="anonymous"></script>
<script src="https://files.codepedia.info/files/uploads/iScripts/html2canvas.js"></script>
</head>
<body>
<div id="container" style="background-color: aliceblue; max-width:400px;">
<h3>
What is Lorem Ipsum?
</h3>
<hr />
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<br/>
<h3>SnapShot :</h3>
<span id="previewImage"></span>
<script>
$(document).ready(function () {
var element = $("#container");
var getCanvas;
html2canvas(element, {
onrendered: function (canvas) {
$("#previewImage").append(canvas);
getCanvas = canvas;
}
});
});
</script>
</body>
</html>