Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 4393 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
685 System/OS [linux] 프로세스의 stat 상태에 대한 설명 hooni 2013.04.23 11887
684 Develop [php] 빔 프로젝터 예약 프로그램.. ㅋㅋ file hooni 2013.04.23 7974
683 Develop [php] 논문 관리 프로그램.. ㅋㅋ file hooni 2013.04.23 7972
682 Develop [c++] 프리렉(freelec) 예제 자료.. ㅋㄷ file hooni 2013.04.23 7830
681 Develop [c++] 템플릿(Template) 예제 소스.. file hooni 2013.04.23 7968
680 Develop [php] 현재에서 일정한 날짜 더하기.. hooni 2013.04.23 8451
679 Develop [c++] 문자열 뒤집기(문자열 거꾸로 출력) hooni 2013.04.23 18079
678 Develop [C++] 18일차 과제물, String 클래스 디자인 【 C++ 문제 】 hooni 2013.04.23 8161
677 Develop [php] 이미지 회전시키기(gd) hooni 2013.04.23 8216
676 Develop [js] 서서히 나타나는 화면.. ㅋㅋ hooni 2013.04.23 7181
675 PPT [doc] 논문.. VoIP 관련.. ㅋㅋ file hooni 2013.04.23 18042
674 System/OS [linux] ssh에서 원격 파일 전송하기.. hooni 2013.04.23 15044
Board Pagination Prev 1 ... 37 38 39 40 41 42 43 44 45 46 ... 99 Next
/ 99