5

I am trying to do a copy to clipboard action by using below code, and the code works fine in desktop browsers but when it comes to mobile browsers like IOS safari/chrome the page scrolls down at $temp.val(copydatacode).select();

 $('#myelementcopy').click(function(event){         
        var copydatacode= $('.addelement').html();
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val(copydatacode).select(); // when the code execute at this line the mobile browser jumps to the page bottom                     
        document.execCommand("copy");           
        $temp.remove(); 
        return false;
        event.preventDefault();         
 });
krish kr
  • 857
  • 1
  • 6
  • 7

1 Answers1

0

I am searching for a perfect solution to this but right now instead of appending to body I append to the element being tapped. This results in a small scroll instead of all the way to the bottom of the page. In jQuery, I used:

$(this).append($temp);
Irfanullah Jan
  • 3,336
  • 4
  • 24
  • 34