Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

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