Download img created on the fly
-
06-07-2021 - |
문제
I create img element with a jquery plugin.
I would like to be able to click a button element and dowload the img element.
Is it possible without HTML5?
I do not store the image, cause it is created on the fly by jquery.
i'm using this plugin to create the img: http://www.class.pm/files/jquery/jquery.uqr/demo/
해결책
Since this is from a different domain, you won't be able to access image contents, unless you try to use CORS - and even then, there's very limited browser support. Use this plugin instead and then use toDataURL() to save it.
다른 팁
The plugin you linked is using Google's deprecated Image Charts portion of Google Charts. Since the images come from a remote server, you can't access them (from JavaScript. Of course you can load them) from your domain (it would be a form of XSS). You can make a PHP script to download a chart and change the Content-Type. When the client requests a PHP script that returns a document with Content-Type application/octet-stream, the download will commence.