Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 1181 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
681 Develop [c++]현승이가 보내준 동영상 암호화 자료.. 볼것.. file hooni 2003.04.23 9729
680 Develop [php] 자주 쓰는 PHP 함수와 예제 hooni 2013.04.23 9705
679 Develop [c] 오목.. 간단한 소스 ㅋㅋ file hooni 2013.04.23 9658
678 Develop OpenGL 강좌 사이트 모음 hooni 2013.04.23 9640
677 Develop [c] 이진트리(binary tree)의 특성 file hooni 2003.04.23 9610
676 Develop [js] Closure를 이용해 캡슐화.. hooni 2013.12.16 9596
675 Develop [c++] 마방진 소스코드 file hooni 2013.04.23 9558
674 Develop [c++] 링크리스트(linked list) 클래스(스택,큐) file hooni 2003.04.23 9553
673 Develop [c] 파일(File)의 연결과 연결 해제 (link, unlink, chown) hooni 2013.04.23 9545
672 Develop [c] 팩토리얼.. - 재귀함수 hooni 2003.04.23 9503
671 Develop [java] 거스름돈 계산.. swing 사용 file hooni 2013.04.23 9446
670 Develop [java] 스윙(swing)버튼 테스트 ㅋㅋ file hooni 2013.04.23 9425
Board Pagination Prev 1 ... 37 38 39 40 41 42 43 44 45 46 ... 98 Next
/ 98