用户捕获div作为图像并保存到计算机 [英] user capture div as image and save to computer
问题描述
我在我的网站上有一个Div,我想放置一个按钮/链接(或其他类似的东西),点击后可以将div及其所有内容保存到用户计算机上,就像打印代码一样用于打印div。我是一个编码新手,所以所有的帮助都会有所帮助。
I have a Div on my site, I want to place a button/link (or other things of the sort) that when clicked will save the div and all its contents to the users computer, much like the printing code which is used to print divs. I'm a coding novice so all help will be apreciated.
推荐答案
有这样的浏览器支持限制。 HTML2Canvas 可以将您的HTML内容呈现为画布
元件。然后你可以使用 canvas.toDataURL(image / png);
( MDN中的文档)方法将 canvas 元素导出为
jpeg
或 png
图片。
There is a browser support limit doing this. HTML2Canvas can render your HTML content into a canvas
element. Then you can use canvas.toDataURL("image/png");
(docs in MDN) method to export the canvas
element to an jpeg
or png
image.
这不是广泛支持,但仍然有可能。
It's not widely supported but it's still possible.
这篇关于用户捕获div作为图像并保存到计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!