如何将html div保存为图像?

时间:2012-01-04 15:01:45

标签: html svg

我在DIV中渲染SVG图像,现在按下按钮我需要将DIV保存为图像,图像应该与我们在屏幕上看到的相同。

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

好吧,这很简单: 首先,你必须使这个功能DownloadImage将图像保存到你的电脑,只需要将图像的网址和名称保存到

DownloadImage= function(picname, dirpath) {

// This method downloads the slide at the specified resolution.


var newwindow;

obj = dirpath+picname

newWindow = window.open( obj, "SaveImage",
"directories=no,status=no,menubar=no,toolbar=no,resizable=no,top=100000,left=100000,width=0,height=0 ");
newWindow.document.execCommand('SaveAs', true);
newWindow.close();
return false;
}

下一步是使用Javascript代码,您必须选择Div DOM OBJECT必需并获取Src attribute并将其传递给上面的函数

相关问题