Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 1273 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
1041 PPT [ppt] 보안경제학 발표자료 secret hooni 2016.11.11 5
1040 Develop [Android Error] The number of method references in a .dex file cannot exceed 64K hooni 2016.11.10 880
1039 Develop [android] 레이아웃 사이즈 변경 (동적; programmatically) hooni 2016.11.07 1597
1038 Develop [android] 초간단 얼럿 (AlertDialog) hooni 2016.10.21 929
1037 Develop [android] dp, px 서로 변환 hooni 2016.10.21 3493
1036 Develop [matlab] ZigZag-Scanning (2-D Array) file hooni 2016.10.15 2099
1035 System/OS [mac] OS X 엘 캐피탄에서 Soudflower 사용하기 2 file hooni 2016.10.03 1157
1034 System/OS [mac] Mac OS에서 재생되는 사운드를 녹음하는 방법 file hooni 2016.10.03 1728
1033 Develop [matlab] 정보은닉 스테가노그래피(Steganography) 수업 file hooni 2016.10.03 780
1032 Develop [c] RSA 암호화 구현(gmp 라이브러리 활용) file hooni 2016.10.03 1000
1031 Develop [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 hooni 2016.10.03 1427
1030 Develop [c] 셀프 넘버(Self Number) 구하기 1 hooni 2016.09.09 2371
Board Pagination Prev 1 ... 7 8 9 10 11 12 13 14 15 16 ... 98 Next
/ 98