We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Copy link/url on click and touch

Home Forums Programming Copy link/url on click and touch

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #56880
    Mariusz
    Customer

    Hi! I have a button with a script attached to it: on click, it copies the URL, so the user can share the link to the configurator (with all the parameters added) with other people. It works perfectly fine on desktop with a mouse click. But it doesn’t work on mobile – I think the problem is that the user “touches” the screen instead of “clicking” it. Can anyone help me modify the code below so it will work both on click and on touch? :) Thanks!

    <script>
    $(document).ready(function(){
    var $temp = $("<input>");
    $('#share_link').click(function() {
    var $url = $(location).attr('href');
    $("body").append($temp);
    $temp.val($url).select();
    document.execCommand("copy");
    $temp.remove();
    });
    });
    </script>
    #56888
    kdv
    Participant

    It’s fully working script. Nothing to fix. It works on iPhone and it works in the mobile emulator in the Google Chrome. Just copies the current page URL when the element with id “share_link” is clicked/touched. In this case it doesn’t matter whether you click the link or touch it.

    You can remove this string to see if the input field $temp is created
    $temp.remove();

    Puzzles and JS. Fast and expensive.

    If you don’t see the meaning in something it primarily means that you just don’t see it but not the absence of meaning at all.

    #57057
    Mariusz
    Customer

    Thank you kdv77kdv! Your words that it should be working correctly inspired me to search for the reason not in the code itself. And eventually, I figured out that the code was fine but I put it in the wrong place! :wacko: I work in Webflow, and I attached this script directly to the button. And it should be pasted just before the </body> tag. When I changed its location it worked as expected. :)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.