Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

조회 수 1179 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
241 Develop [pdf] C 국제 표준 문서 file hooni 2013.04.23 6743
240 Develop [c] 싱글, 더블 링크리스트(linked list)로 만든 예제.. file hooni 2003.04.23 6737
239 Develop [c] 소켓주소 구조체에 대해.. hooni 2003.04.23 6731
238 Develop [js] 이벤트 핸들러(Event Handlers) hooni 2003.04.23 6729
237 Develop [js] 가운데 새창 뜨는 함수와 이벤트 hooni 2003.04.23 6723
236 Develop [c] 서비스 거부 공격(DoS;Denial of Service) 간단 소스.. ㅋㅋ file hooni 2013.04.23 6718
235 Develop [php] 서버 이상 체크 해서 문자보내는 샘플소스.. file hooni 2013.04.23 6693
234 Develop [c++] 헤더, 소스 파일 분리해서 작성해본 테스트 소스 file hooni 2013.04.23 6688
233 Develop [java] 스윙(swing) 인터페이스 이용해서 만든 구구단.. ㅋㅋ file hooni 2003.04.23 6682
232 Develop [c] 컴파일러 선행처리기 따라하기.. file hooni 2003.04.23 6681
231 Develop [c] alarm()함수 설명과 간단한 예제 file hooni 2013.04.23 6678
230 Develop [js] 스타크래프트(starcraft).. file hooni 2013.04.23 6641
Board Pagination Prev 1 ... 46 47 48 49 50 51 52 53 54 55 ... 71 Next
/ 71