Copy Text With JS

Copy Text With JS

I found this jewel somewhere:

var element = this.parentView.get('element')
var snippet = element.getElementsByClassName('snippet')
var selection = window.getSelection();

if(selection.rangeCount > 0) selection.removeAllRanges();

for(var i = 0; i < snippet.length; i++) {
  var range = document.createRange();
  range.selectNode(snippet[i]);
  selection.addRange(range);

  document.execCommand("copy");
}

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *