Automatically Download Images Upon Click (jQuery)
-
Hello Armin and Crew,
I'm trying to get images to automatically download upon click and can't seem to crack the code. I read up on the particulars of your 'bind to click' jquery on the site and have tried to approximate mine based on some other web tutorials, but can't seem to crack it.
Here's what I have now:
jQuery(document).on("click", ".clickme", function(event){
var link = $(“<a></a>”);
var source = $(this).attr(“src”)
link.attr(“href”, source);
link.attr(“download”, “filename”)
link.attr(“target”, “_blank”)
JQuery(link).css(“display”, ”none”);
JQuery(“body”).append(link);
link.click()
JQuery(link).remove()
})Does not seem to do anything -- any advice?
Thanks so much!
Kurt
-
Dear @kurtwoerpel
do you have many images?
You could just link them to the image file from your MEDIA LIBRARY.I think your jQuery code is a bit too complicated.
I would make a JS Fiddle to test.
Not sure if you need this:
var link = $(“<a></a>”);You just need the Source and then open the source again in a new window.
Best!
Marius
-
Hmmmmm.
I will fiddle around ;)
I'm having trouble even having jQuery recognize or trigger from images.
Is there a specific way i have to refer to images in LayTheme? -
Dear @kurtwoerpel
give this a try.
<script> jQuery(document).on("click", "img", function(event) { jQuery(this).addCLass("TEST"); }); </script>Best!
Marius
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login