jquery - add download function to a click event with Javascript -


i wondering if possible add download function click event purely in javascript, example, when user clicks on image, gets automatically downloaded. example have image tag <img src="filelocation" id="img"/> , want downloaded on click. (i can't use "download="myfile.png".

is there

$('#img').on('click',function(e){   img.download="myfile.png"; }); 

all answers online suggest adding download="..." tag

thanks!

maybe this:

document.getelementbyid('download').click();
<a id="download" href="https://assets.entrepreneur.com/content/16x9/822/20150721193719-solshero3.jpeg" download hidden></a>

play it: here

but if can't have download attribute: play then.

good luck!!


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -