Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 1167 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
745 Develop [js] 자바스크립트(Javascript) 코드를 동적으로 삽입하는 방법.. file hooni 2013.04.23 22875
744 Develop [ios] UILabel top alignㅎㅎ hooni 2013.04.23 22840
743 Develop 밸런싱 로봇.. 최종.. (관련 논문도 첨부) ㅋㅋ file hooni 2013.04.23 22818
742 Develop [vb] 문자열에서 태그 제거함수 (Visual Basic) file hooni 2013.04.23 22621
741 Develop [iphone] 화면 전환 Portrait & Landscape Mode hooni 2013.04.23 22308
740 Develop [doc] Json Framework 설치와 사용 file hooni 2013.04.23 21916
739 Develop [c] 재미있는 코딩.. file hooni 2003.04.23 21316
738 Develop 프로그래밍에서 foo, bar 함수의 유래 file hooni 2013.06.25 21247
737 Develop [c] 포인터 학습용 예제 소스 코드 file hooni 2013.04.23 21029
736 Develop [c] 이진트리/트리 순회법 코드(전위/중위/후위) 5 file hooni 2015.07.02 20918
735 Develop git 브런치 배우기 (링크) hooni 2013.07.09 20571
734 Develop [c++] 디렉토리 내의 파일 찾기 FindFirstFile() 함수 6 hooni 2013.04.23 20569
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 71 Next
/ 71