2

need some help. How do i change the below code so that i can create when user clicks the button a image tag will be copy to the clipboard and and user can paste it in the address bar

<?php
$arr = array('1'=>'goo.gl/kgVQMc', '2'=>'goo.gl/cqhk1V');
?>

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  </head>
  <body>

    <?php
    foreach($arr as $key => $value)
    {
      ?>
      <p id="<?php echo $key?>"> <?php echo $value?> </p>
      <button onclick="copyToClipboard('#<?php echo $key?>')">Copy Text<?php echo $key?></button>
      <br><br>
      <?php
    }
    ?>

    <input type="text">

    <script type="text/javascript">
      function copyToClipboard(element) {
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val($(element).text()).select();
        document.execCommand("copy");
        $temp.remove();
      }
    </script>

  </body>
</html>
Nikhil Parmar
  • 495
  • 3
  • 17
  • I found https://stackoverflow.com/questions/39787005/copy-img-tag-to-clipboard-with-javascript and https://stackoverflow.com/questions/33175909/copy-image-to-clipboard Please review and I am also checking if I can help you more. – Nikhil Parmar Sep 16 '17 at 04:54

0 Answers0