Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 4403 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




?

List of Articles
No. Category Subject Author Date Views
1141 Develop [php] 3 Ways to Detect Mobile or Desktop in PHP file hooni 2020.01.28 7617
1140 Develop 자주 쓰는 Docker 명령어 alias hooni 2020.01.10 289649
1139 Develop [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기) hooni 2019.12.06 3693
1138 System/OS SSH Passwordless Login Using SSH Keygen in 5 Easy Steps file hooni 2019.11.22 4222
1137 System/OS [virtualbox] VirtualBox에 Ubuntu 설치하기 file hooni 2019.11.22 2658
1136 Database [mysql] MySQL 데이터베이스 추가 및 사용자 추가 hooni 2019.11.22 3095
1135 Database [oracle] Oracle 사용자 추가 절차 hooni 2019.11.22 2668
1134 Database [mysql] MySQL 백업 및 복구 hooni 2019.11.22 2899
1133 Database [mysql] MySql DB/테이블 사이즈 확인을 위한 쿼리 hooni 2019.11.22 2642
1132 Database SQL JOIN 정리 (Inner Join & Outer Join) file hooni 2019.11.22 3941
1131 Develop [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) hooni 2019.11.22 3793
1130 Develop 링크들 보고 지울 내용 secret hooni 2019.11.21 0
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99