function appendCopyToClipBoardButton(text, node) {
  if (!document.queryCommandSupported ||
      !document.queryCommandSupported('copy')) {
    // Don't add copy to clipboard button if not supported.
    return;
  }
  let copyButton = document.createElement('div');
  copyButton.setAttribute('class', 'copy-to-clipboard-button');
  copyButton.textContent = 'Copy';

  copyButton.addEventListener('click', () => {
    var textarea = document.createElement('textarea');
    textarea.textContent = text;
    document.body.appendChild(textarea);
    textarea.select();
    try {
      return document.execCommand('copy');  // Security exception may be thrown.
    } catch (ex) {
      console.warn('Copy to clipboard failed.', ex);
      return false;
    } finally {
      document.body.removeChild(textarea);
    }
  });
  node.appendChild(copyButton);
}
/**
 * Create and add a copy to clipboard button to a given node.
 *
 * @param {string} text The text that will be copied to the clipboard.
 * @param {element!} node The node that will have the button appended to.
 */
Create and add a copy to clipboard button to a given node.
@param {string} text The text that will be copied to the clipboard.
@param {element!} node The node that will have the button appended to.
Create and add a copy to clipboard button to a given node . @param { string } text The text that will be copied to the clipboard . @param { element! } node The node that will have the button appended to .
function appendCopyToClipBoardButton(text, node) {
  if (!document.queryCommandSupported ||
      !document.queryCommandSupported('copy')) {
    return;
  }
  let copyButton = document.createElement('div');
  copyButton.setAttribute('class', 'copy-to-clipboard-button');
  copyButton.textContent = 'Copy';
  copyButton.addEventListener('click', () => {
    var textarea = document.createElement('textarea');
    textarea.textContent = text;
    document.body.appendChild(textarea);
    textarea.select();
    try {
      return document.execCommand('copy');  
    } catch (ex) {
      console.warn('Copy to clipboard failed.', ex);
      return false;
    } finally {
      document.body.removeChild(textarea);
    }
  });
  node.appendChild(copyButton);
}
function appendCopyToClipBoardButton ( text , node ) { if ( ! document . queryCommandSupported || ! document . queryCommandSupported ( 'copy' ) ) { return ; } let copyButton = document . createElement ( 'div' ) ; copyButton . setAttribute ( 'class' , 'copy-to-clipboard-button' ) ; copyButton . textContent = 'Copy' ; copyButton . addEventListener ( 'click' , ( ) => { var textarea = document . createElement ( 'textarea' ) ; textarea . textContent = text ; document . body . appendChild ( textarea ) ; textarea . select ( ) ; try { return document . execCommand ( 'copy' ) ; } catch ( ex ) { console . warn ( 'Copy to clipboard failed.' , ex ) ; return false ; } finally { document . body . removeChild ( textarea ) ; } } ) ; node . appendChild ( copyButton ) ; }
Create and add a copy to clipboard button to a given node.
Create and add a copy to clipboard button to a given node .
// Don't add copy to clipboard button if not supported. // Security exception may be thrown.