Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  176] [ 1]  / answers: 1 / hits: 15167  / 13 Years ago, wed, may 18, 2011, 12:00:00

I am working with canvas and I would be able to save my Canvas to png.



By looking around, I discover the great toDataURL() function given by the W3C.



I am also already using the canvas2image from nihilogic that we can found on this page : http://www.nihilogic.dk/labs/canvas2image/



I noticed that on canvas2image, the developpers use the image/octet-stream which open the open with dialog box but give some problem :



-picture name is the ascii returned by toDataUrl().



-file extension is .part when downloaded



In short, I would prompt the open with dialog box with something like myImage.png when clicking on a button.



Is it possible ? Any help would be appreciated.



Edit : I have the contraint to use only Javascript, I can't use some nice PHP trick


More From » html

 Answers
11

if you aim to only modern browsers and don't care cross-browser that much, there's a possible solution with download attribute of element.
Here's one sample for your information:



<a target=_blank href=https://www.google.com/intl/en_com/images/srpr/logo3w.png download=testXXX.jpg>DOWNLOAD ME!</a>


Only one line, no javascript, yeah! You can change the href part into data url, and that works too.



Check this Eric's tutorial on html5rocks for more details.


[#92179] Tuesday, May 17, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marcos

Total Points: 331
Total Questions: 106
Total Answers: 104

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
marcos questions
Thu, Feb 24, 22, 00:00, 2 Years ago
Sat, Apr 17, 21, 00:00, 3 Years ago
Mon, Feb 1, 21, 00:00, 3 Years ago
Tue, Jan 26, 21, 00:00, 3 Years ago
Wed, Jan 6, 21, 00:00, 3 Years ago
;