Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is There A Way To Store Results Page Contents To Clipboard?

Status
Not open for further replies.

HowdeeDoodee

Technical User
Mar 14, 2005
61
US
Is there a way I can put a hyperlink or button in every cell in a column on a pagination results page so the user can click on the hyperlink or button and store the contents of the cell to the clipboard? Clicking on the button or hyperlink would have the same effect as selecting and copying the cell contents using the browser's edit > copy command.
 
this is more a question for the javascript forum. if this solution doesn't work i suggest you post there. i believe this is only valid for IE. perhaps an execcommand approach will have more x-browser compatibility.

Method:

1. assign each cell content to a $text variable (usually as part of the output from a db?
2. inside each cell put the contents in a link: <td><a href="javascript:void(0);" onclick="copy2clip('<? echo addslashes($text); ?>);'"><?=$text?></a>
3. insert this javascript into the <head> section:
Code:
<script type="text/javascript">
function copy2clip(txt) 
{
  res = window.clipboardData.setData("Text",txt);  
  if (res) 
  {alert ("text copied to clipboard");} 
  else
  { alert ("copy failed");}
}
</script>
 
Thank you for the reply. Each cell is created in the pagination code. Adding the javascript may be a chore and could play havoc with some user's browsers. However, it is worth a shot. If anyone else has any suggestions, please post.
 
JavaScript or VBScript is the only way to do it, as PHP runs on the web server and you need to manipulate the clipboard on the client.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top