如何使用JavaScript将呈现的网页保存为图片? [英] How to save a rendered webpage as image with JavaScript?

查看:122
本文介绍了如何使用JavaScript将呈现的网页保存为图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我必须提供另存为图片按钮。我想将呈现在我的网页上的HTML保存为JavaScript中的图像。这是一个web应用程序,将用于桌面/平板电脑/手机浏览器。如何保存HTML渲染为图像?

In my app I have to provide a 'save as image' button. I want to save the HTML rendered on my webpage as an image in JavaScript. It is a webapp and will be used in browsers of desktop/tablet/mobile phones. How to save rendered HTML as an image?

推荐答案

检查出来的 html2canvas 。在canvas元素上呈现页面内容的JavaScript框架。保存画布作为图像一样简单:

Check out html2canvas. A javascript framework that renders the page content on a canvas element. Saving the canvas as an image is as easy as:

var canvas = document.getElementById("mycanvas");
var img    = canvas.toDataURL("image/png");
document.write('<img src="'+img+'"/>');

来源

这篇关于如何使用JavaScript将呈现的网页保存为图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆