Thursday, January 2, 2020

Copy the guts of an HTML tab, the various cells, into sort of a tab-delimited format at the clipboard.

In cooking this up Friday, I experimented with the following and uncharacteristically failed to document it. I am sort of recreating it from memory here.

var range = document.createRange();
var selection = window.getSelection();
selection.removeAllRanges();
range.selectNodeContents(document.getElementById("touchMe"));
document.execCommand('copy');
selection.removeAllRanges();

 
 

Maybe try .selectNode instead of .selectNodeContents if .selectNodeContents does not work.

No comments:

Post a Comment