Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 1173 Votes 0 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
713 Develop [ios] 동영상 플레이어 샘플 (for Remote Url) file hooni 2017.02.07 1645
712 Develop [ios] @property의 속성 (strong, weak, copy) 사용 경우 hooni 2014.08.08 1658
711 Develop Laravel 5 Failed opening required bootstrap/../vendor/autoload.php hooni 2018.01.24 1660
710 Develop [c] 한글 문자열 출력 hooni 2015.11.10 1680
709 Develop [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기) hooni 2019.12.06 1690
708 Develop [php] mysql_ 과 mysqli_ 의 차이 hooni 2017.12.01 1695
707 Develop [swift] UIView에서 subview 찾기 hooni 2022.12.09 1771
706 Develop [ios] Xcode cannot run using the selected device hooni 2014.08.14 1789
705 Develop [iOS] Xcode 불필요한 캐시 삭제하기 hooni 2021.10.12 1792
704 Develop [iOS] 시뮬레이터에 푸시 알림을 보내는 방법 file hooni 2021.10.13 1814
703 Develop [ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define hooni 2014.08.08 1860
702 Develop [ios] 카메라 사용 권한 확인해서 분기하는 방법 hooni 2015.02.26 1873
701 Develop [php][laravel] 초간단 MacOS에서 Laravel 개발 환경 구축 hooni 2017.12.15 1880
700 Develop [android] 가속도 센서를 이용한 흔듦(Shake) 감지 file hooni 2014.11.04 1898
699 Develop [ios] 웹뷰 history.back() ㅋㄷ file hooni 2016.06.27 1903
698 Develop [matlab] ZigZag-Scanning (2-D Array) file hooni 2016.10.15 1991
Board Pagination Prev 1 ... 7 8 9 10 11 ... 53 Next
/ 53