Trying get this script to copy to the clipboard and not back into the page. When you click the link it should copy right to the clip board. At least that is my intention. Here are some background facts behinds it:
- This is for a company intranet site that uses IE exclusivly so it does not need to be compatible with any other browsers
- The data inside is/will be a return from a db query
I realize this is old technology but it needs to be this way for now.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd"> <html xmlns=""> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"><!-- // input field descriptions var desc = new Array(); desc['a1'] = 'First name'; desc['a2'] = 'Last name'; desc['a3'] = 'Address'; desc['a4'] = 'Zip'; desc['a5'] = 'City'; desc['a6'] = 'Country'; function CopyFields(){ var copytext = ''; for(var i = 0; i < arguments.length; i++){ copytext += desc[arguments[i]] + ': ' + document.getElementById(arguments[i]).innerText + '\n';} var tempstore = document.getElementById(arguments[0]).innerText; document.getElementById(arguments[0]).innerText = copytext; document.getElementById(arguments[0]).focus(); document.getElementById(arguments[0]).select(); document.execCommand('Copy'); document.getElementById(arguments[0]).innerText = tempstore; } </script> </head> <body> <table> <tr> <td id="a1" name="t1">a</td> <td id="a2" name="t2">b</td> <td id="a3" name="t3">c</td> <td id="a4" name="t4">d</td> <td id="a5" name="t5">e</td> <td id="a6" name="t6">f</td> </tr> </table><br> <a href="#" onClick="CopyFields('a1', 'a2', 'a3', 'a4', 'a5', 'a6');">Copy values of text fields to clipboard</a> </body> </html>
Trying get this script to copy to the clipboard and not back into the page. When you click the link it should copy right to the clip board. At least that is my intention. Here are some background facts behinds it:
- This is for a company intranet site that uses IE exclusivly so it does not need to be compatible with any other browsers
- The data inside is/will be a return from a db query
I realize this is old technology but it needs to be this way for now.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"><!-- // input field descriptions var desc = new Array(); desc['a1'] = 'First name'; desc['a2'] = 'Last name'; desc['a3'] = 'Address'; desc['a4'] = 'Zip'; desc['a5'] = 'City'; desc['a6'] = 'Country'; function CopyFields(){ var copytext = ''; for(var i = 0; i < arguments.length; i++){ copytext += desc[arguments[i]] + ': ' + document.getElementById(arguments[i]).innerText + '\n';} var tempstore = document.getElementById(arguments[0]).innerText; document.getElementById(arguments[0]).innerText = copytext; document.getElementById(arguments[0]).focus(); document.getElementById(arguments[0]).select(); document.execCommand('Copy'); document.getElementById(arguments[0]).innerText = tempstore; } </script> </head> <body> <table> <tr> <td id="a1" name="t1">a</td> <td id="a2" name="t2">b</td> <td id="a3" name="t3">c</td> <td id="a4" name="t4">d</td> <td id="a5" name="t5">e</td> <td id="a6" name="t6">f</td> </tr> </table><br> <a href="#" onClick="CopyFields('a1', 'a2', 'a3', 'a4', 'a5', 'a6');">Copy values of text fields to clipboard</a> </body> </html>
- 1 So what's not working. – Gabe Commented Apr 11, 2013 at 20:42
- @Gabe When you click the link it should copy the 'desc' and '<td>' data into the clipboard not right back on the page – user1839308 Commented Apr 11, 2013 at 21:24
1 Answer
Reset to default 20there is no select()
-method for td
-elements.
You may directly access the clipboard without using the Copy-command:
window.clipboardData.setData('Text', copytext);