Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 1272 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
1077 Develop [c] RSA 암호화 구현(gmp 라이브러리 활용) file hooni 2016.10.03 1000
1076 PPT 삼성페이(Samsung Pay) 구조 file hooni 2016.09.09 1004
1075 Develop [js] AngularJS 란? file hooni 2015.11.26 1009
1074 Develop XE Core 1.8.18 본문 작성시 태그(html) 사라지는 버그 file hooni 2016.04.21 1009
1073 System/OS [mac] How to uninstall MySQL on Mac OS. hooni 2017.11.08 1021
1072 System/OS [virtualbox] VirtualBox에 Ubuntu 설치하기 file hooni 2019.11.22 1046
1071 Develop [ios] 로컬에 있는 JS 파일 웹뷰에서 동적으로 실행하기 hooni 2015.02.10 1061
1070 Develop [ios] 오브젝티브C→스위프트, 코드 변환 손쉽게 file hooni 2015.08.07 1065
1069 Develop [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법 file hooni 2017.03.29 1065
1068 Develop [android] 딜레이를 구현하기 위한 꼼수 hooni 2016.11.24 1068
1067 Develop [ubuntu] 우분투 18.04에 PHP5 설치하기 hooni 2020.11.14 1073
1066 Develop [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태 hooni 2018.10.19 1074
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 98 Next
/ 98