Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 4402 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

Example no jQuery.


# JAVASCRIPT

function copyToClipboard(elementId) {

  // Create a "hidden" input
  var aux = document.createElement("input");

  // Assign it the value of the specified element
  aux.setAttribute("value", document.getElementById(elementId).innerHTML);

  // Append it to the body
  document.body.appendChild(aux);

  // Highlight its content
  aux.select();

  // Copy the highlighted text
  document.execCommand("copy");

  // Remove it from the body
  document.body.removeChild(aux);

}


# HTML

<p id="p1">P1: I am paragraph 1</p>
<p id="p2">P2: I am a second paragraph</p>
<button onclick="copyToClipboard('p1')">Copy P1</button>
<button onclick="copyToClipboard('p2')">Copy P2</button>
<br/><br/><input type="text" placeholder="Paste here for test" />



[출처] https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery




?

  1. [php] 3 Ways to Detect Mobile or Desktop in PHP

  2. 자주 쓰는 Docker 명령어 alias

  3. [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기)

  4. SSH Passwordless Login Using SSH Keygen in 5 Easy Steps

  5. [virtualbox] VirtualBox에 Ubuntu 설치하기

  6. [mysql] MySQL 데이터베이스 추가 및 사용자 추가

  7. [oracle] Oracle 사용자 추가 절차

  8. [mysql] MySQL 백업 및 복구

  9. [mysql] MySql DB/테이블 사이즈 확인을 위한 쿼리

  10. SQL JOIN 정리 (Inner Join & Outer Join)

  11. [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs)

  12. 링크들 보고 지울 내용

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99