Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 1309 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
37 Develop [android] ArrayAdapter 테스트 파일 ㅎㅎ hooni 2013.04.23 45298
36 Develop [ios] 배열(NSArray) 연산과 간단한 애니메이션(split images) hooni 2013.10.31 45602
35 Develop [ios] UIAlertView 초간단 샘플 ㅎㅎ hooni 2013.10.14 46208
34 Develop [android] ArrayAdapter를 이용하여 출력하기 hooni 2013.04.23 47397
33 Develop [android]개발 가이드 및 한글화 문서 file hooni 2013.04.23 47566
32 Develop [android] GCM 사용하기 1 (GCM 서비스 신청하기) file hooni 2013.07.06 51430
31 Develop [vb] 비쥬얼 베이직으로.. hooni 2003.04.23 53139
30 Develop [iphone] view에 대한 조사 ㅡ,.ㅡ; file hooni 2013.04.23 54121
29 Develop [vb] 비쥬얼 베이직 기출 문제 연습2 hooni 2003.04.23 54457
28 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 54923
27 Develop [vb] 비쥬얼 베이직 기출 문제 연습 hooni 2003.04.23 55252
26 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 56147
Board Pagination Prev 1 ... 62 63 64 65 66 67 68 69 70 71 Next
/ 71