Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 1285 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
141 Develop [matlab] 정보은닉 스테가노그래피(Steganography) 수업 file hooni 2016.10.03 783
140 System/OS [mac] Mac OS에서 재생되는 사운드를 녹음하는 방법 file hooni 2016.10.03 1733
139 System/OS [mac] OS X 엘 캐피탄에서 Soudflower 사용하기 2 file hooni 2016.10.03 1163
138 Develop [matlab] ZigZag-Scanning (2-D Array) file hooni 2016.10.15 2107
137 Develop [android] dp, px 서로 변환 hooni 2016.10.21 3496
136 Develop [android] 초간단 얼럿 (AlertDialog) hooni 2016.10.21 932
135 Develop [android] 레이아웃 사이즈 변경 (동적; programmatically) hooni 2016.11.07 1603
134 Develop [Android Error] The number of method references in a .dex file cannot exceed 64K hooni 2016.11.10 886
133 PPT [ppt] 보안경제학 발표자료 secret hooni 2016.11.11 5
132 Develop [android] Calling activity function from separate class hooni 2016.11.15 1303
131 Develop [android] How can I place app icon on launcher home screen? hooni 2016.11.15 1401
130 Develop [android] 딜레이를 구현하기 위한 꼼수 hooni 2016.11.24 1071
Board Pagination Prev 1 ... 82 83 84 85 86 87 88 89 90 91 ... 98 Next
/ 98