Copy Text to Clipboard

blogphp18 thg4 2019
Javascript

Example

<!-- The text field -->
<input type="text"value="Hello World"id="myInput">

<!-- The button used to copy the text -->
<buttononclick="myFunction()">Copy text</button>

Step 2) Add JavaScript:

Example

function myFunction() {
  /* Get the text field */
  var copyText = document.getElementById("myInput");

  /* Select the text field */
  copyText.select();

  /* Copy the text inside the text field */
  document.execCommand("copy");

  /* Alert the copied text */
  alert("Copied the text: " + copyText.value);
}

Gửi bài viết tới Facebook

Gửi hình ảnh