Contents

Develop
2018.04.05 09:57

[js] Click button copy to clipboard

Views 4398 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




?

  1. [php] 3 Ways to Detect Mobile or Desktop in PHP

    Date2020.01.28 CategoryDevelop Byhooni Views7604
    Read More
  2. 자주 쓰는 Docker 명령어 alias

    Date2020.01.10 CategoryDevelop Byhooni Views289467
    Read More
  3. [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기)

    Date2019.12.06 CategoryDevelop Byhooni Views3682
    Read More
  4. SSH Passwordless Login Using SSH Keygen in 5 Easy Steps

    Date2019.11.22 CategorySystem/OS Byhooni Views4131
    Read More
  5. [virtualbox] VirtualBox에 Ubuntu 설치하기

    Date2019.11.22 CategorySystem/OS Byhooni Views2643
    Read More
  6. [mysql] MySQL 데이터베이스 추가 및 사용자 추가

    Date2019.11.22 CategoryDatabase Byhooni Views3083
    Read More
  7. [oracle] Oracle 사용자 추가 절차

    Date2019.11.22 CategoryDatabase Byhooni Views2654
    Read More
  8. [mysql] MySQL 백업 및 복구

    Date2019.11.22 CategoryDatabase Byhooni Views2885
    Read More
  9. [mysql] MySql DB/테이블 사이즈 확인을 위한 쿼리

    Date2019.11.22 CategoryDatabase Byhooni Views2627
    Read More
  10. SQL JOIN 정리 (Inner Join & Outer Join)

    Date2019.11.22 CategoryDatabase Byhooni Views3929
    Read More
  11. [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs)

    Date2019.11.22 CategoryDevelop Byhooni Views3784
    Read More
  12. 링크들 보고 지울 내용

    Date2019.11.21 CategoryDevelop Byhooni Views0
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99