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:
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>
Open the file that you want to copy items from. Select the first item that you want to copy, and press CTRL+C. Continue copying items from the same or other files until you have collected all of the items that you want. The Office Clipboard can hold up to 24 items.
Select the text or graphics you want to copy, and press Ctrl+C. Each selection appears in the Clipboard, with the latest at the top. Optionally, repeat step 2 until you've copied all the items you want to use. Tip: After you open the Clipboard, it stores content that you copy or cut from anywhere.
Whether it is a sample of code or it is the User's own information, we can create a copy button to copy data to the clipboard using the navigator. clipboard. writeText() function. This function writes the data fed to it as a parameter into the clipboard.
there is no select()
-method for td
-elements.
You may directly access the clipboard without using the Copy-command:
window.clipboardData.setData('Text', copytext);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With