Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 1307 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
817 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 57264
816 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 56144
815 Develop [vb] 비쥬얼 베이직 기출 문제 연습 hooni 2003.04.23 55248
814 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 54922
813 Develop [vb] 비쥬얼 베이직 기출 문제 연습2 hooni 2003.04.23 54456
812 Develop [iphone] view에 대한 조사 ㅡ,.ㅡ; file hooni 2013.04.23 54120
811 Develop [vb] 비쥬얼 베이직으로.. hooni 2003.04.23 53135
810 Develop [android] GCM 사용하기 1 (GCM 서비스 신청하기) file hooni 2013.07.06 51430
809 Develop [android]개발 가이드 및 한글화 문서 file hooni 2013.04.23 47565
808 Develop [android] ArrayAdapter를 이용하여 출력하기 hooni 2013.04.23 47397
807 Develop [ios] UIAlertView 초간단 샘플 ㅎㅎ hooni 2013.10.14 46207
806 Develop [ios] 배열(NSArray) 연산과 간단한 애니메이션(split images) hooni 2013.10.31 45597
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 71 Next
/ 71