Advertisement
Guest User

Untitled

a guest
Jun 5th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function copyToClipboard(elementId) {
  2.  
  3.   // Create an auxiliary hidden input
  4.   var aux = document.createElement("input");
  5.  
  6.   // Get the text from the element passed into the input
  7.   aux.setAttribute("value", document.getElementById(elementId).innerHTML);
  8.   aux.replace(/<br\s*[\/]?>/gi, "\n");
  9.  
  10.   // Append the aux input to the body
  11.   document.body.appendChild(aux);
  12.  
  13.   // Highlight the content
  14.   aux.select();
  15.  
  16.  
  17.   // Execute the copy command
  18.   document.execCommand("copy");
  19.  
  20.   // Remove the input from the body
  21.   document.body.removeChild(aux);
  22.  
  23. }
  24.  
  25. function log(){
  26.     console.log('---')
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement