Click the button and Copy to Clipboard
First, create an input box and put value s into the input box, which data you want to share, then define a button give a button name.
Follow HTML Code:
<div class="col-md-6" style=""> <input type="text" id="copyInput" value="https://datainflow.com" readonly> <!-- copyInput is the input ID you can change it AND https://datainflow.com this is the example data you can put your data--> <button id="ClickButton" class="sign-in">Copy share Link</button> </div>
Add jquery-3.2.1.min.js or copy from below:
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
Apply this code below of the jquery-3.2.1.min.js.
<script> document.getElementById("ClickButton").addEventListener("click", function() { copyToClipboard(document.getElementById("copyInput")); // put the same name(copyInput) which you have put in the input box. }); function copyToClipboard(elem) { var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA"; if (isInput) { target = elem; } // select the content var currentFocus = document.activeElement; target.focus(); target.setSelectionRange(0, target.value.length); // copy the selection var succeed; try { succeed = document.execCommand("copy"); } catch(e) { succeed = false; } return succeed; } </script>
Hope this example code will be helpful for you.
Question and answer is powered by AnsPress.io