user capture div as image and save to computer

Jack Notman picture Jack Notman · Nov 6, 2011 · Viewed 39.8k times · Source

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.

Answer

Mohsen picture Mohsen · Nov 6, 2011

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.