2 function clipboardcopy(val) {
3 if (window && window.clipboardData) {
5 return window.clipboardData.setData('text', val);
8 if (document.queryCommandSupported('copy')) {
9 var textArea = document.createElement('textarea');
11 // minimise styling in case it is (briefly) rendered
12 textArea.style.position = 'fixed';
13 textArea.style.top = 0;
14 textArea.style.left = 0;
15 textArea.style.width = '2em';
16 textArea.style.height = '2em';
17 textArea.style.padding = 0;
18 textArea.style.border = 'none';
19 textArea.style.outline = 'none';
20 textArea.style.boxShadow = 'none';
21 textArea.style.background = 'transparent';
23 // temporarily add input field to copy text from
25 document.body.appendChild(textArea);
28 document.execCommand('copy');
30 console.log('could not copy "'+val+'" to clipboard');
32 document.body.removeChild(textArea);
36 charmatch = /^U\+([0-9A-F]{4,})/;
37 function copycellchars() {
38 var unicode = charmatch.exec(this.title);
39 var str = String.fromCharCode(parseInt(unicode[1], 16));
40 return clipboardcopy(str);
43 var cells = document.getElementsByTagName('TD');
44 for (var i = 0; i < cells.length; i++) {
45 if (!cells[i].title) continue;
46 if (!charmatch.test(cells[i].title)) continue;
47 cells[i].onclick = copycellchars;