JS browser Copy

function copyArticle() {
  const range = document.createRange();
  range.selectNode(document.getElementById('content'));
  const selection = window.getSelection();
  if(selection.rangeCount > 0) selection.removeAllRanges();
  selection.addRange(range);
  document.execCommand('copy');
  alert ( "copy success!");
  }
  document.getElementById('copyBT').addEventListener('click', copyArticle, false); 

Guess you like

Origin www.cnblogs.com/jyc226/p/11606874.html