I am working on a QR Code project and some image is generated via Canvas. So they are not actually images. And users can't download/save it by hitting a "save as" context menu item.
How do I let the users able to download it?
I am working on a QR Code project and some image is generated via Canvas. So they are not actually images. And users can't download/save it by hitting a "save as" context menu item.
How do I let the users able to download it?
Assuming your "Save as" button look something like this (uninitialized, see below):
<a href="#" id="saveas" download="">Save as</a>
Then when you have created the QR code on canvas do the following to initialize it:
/// QR created here..
var link = document.getElementById('saveas');
link.download = 'filename.png'; /// set a filename or a default
link.href = canvas.toDataURL(); /// create a data-uri as link
The key here is the new download attribute for the anchor tag. This will pop up a save as requester instead of navigating to the image.
You can also chose to hide the link and show it when it's initialized. You get the idea..
canvas.toDataURL() is a native supported method?