Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 4403 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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
번호 분류 제목 글쓴이 날짜 조회 수
204 System/OS Apache CORS 설정 1 hooni 2020.09.04 6145
203 System/OS asx미디어 정보 기록.. hooni 2003.04.23 22159
202 System/OS Brave Browser for Debian, Ubuntu, Mint file hooni 2024.10.23 6976
201 System/OS CentOS 6.5 USB 설치 6 file hooni 2013.12.18 39988
200 System/OS CentOS 에서 Cacti 설치하기 hooni 2015.01.02 3189
199 System/OS Configure Postfix to Use Gmail SMTP on Ubuntu 18.04 file hooni 2020.02.07 12277
198 System/OS Enable Safari Hidden Debug Menu in Mac OS X file hooni 2017.02.07 7655
197 System/OS Enable the Develop Menu in Safari file hooni 2017.02.07 4122
196 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 5596
195 System/OS How to Setup an Email Server on CentOS 7 hooni 2018.04.05 5919
194 System/OS HTTP 프로토콜 (브라우저와 웹서버 간의 통신) hooni 2003.04.23 50785
193 System/OS HTTPS와 SSL 인증서 file hooni 2014.03.11 8768
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 17 Next
/ 17