Lay Theme Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Search

    Automatically Download Images Upon Click (jQuery)

    General Discussion
    2
    4
    276
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kurtwoerpel
      kurtwoerpel last edited by

      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

      1 Reply Last reply Reply Quote 0
      • mariusjopen
        mariusjopen Global Moderator last edited by

        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

        www.mariusjopen.world

        1 Reply Last reply Reply Quote 0
        • kurtwoerpel
          kurtwoerpel last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • mariusjopen
            mariusjopen Global Moderator last edited by

            Dear @kurtwoerpel

            give this a try.

            <script>
            jQuery(document).on("click", "img", function(event) {
            	jQuery(this).addCLass("TEST");
            });
            </script>
            

            Best!

            Marius

            www.mariusjopen.world

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Before you post

            Use the Search Feature. Maybe there is already a solution to your issue.

            1. Update Lay Theme and all Lay Theme Addons
            2. Disable all Plugins
            3. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code ", click "Save Changes"
            4. Now see if your problem solved itself
            5. Go here, see if your problem is listed here:
            Troubleshooting

            When you post:
            1. Post a link to where the problem is
            2. If the problem is difficult to explain, post screenshots / link to a video to explain it

            Thanks!

            Online Users

            A
            K
            F
            F
            S
            S

            Recent Topics

            • A

              Theme crashed - because of Polylang?

            • A

              fullscreen slider: slow load time + mobile: images dropping to bottom

            • Unable to Update Add ons (plugins)

            • S

              Links don't work / pages don't show up

            laytheme.com