• Erin Jane 8
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Has anyone successfully created a "Copy to Clipboard" button in Visualforce?

 

I've got a method that works for Internet Explorer only ( http://www.htmlgoodies.com/beyond/javascript/article.php/3458851/Click-Its-Copied.htm) , which will be acceptable at this point, although I would prefer a cross-browser solution.

 

However, I don't seem to be able to make it work in a VF page. Here's my basic attempt:

 

 

<apex:page title="Clipboard Test" showheader="false">

	<script language="JavaScript">
		function ClipBoard()
		{
			holdtext.innerText = {!$Component.copytext}.innerText;
			Copied = holdtext.createTextRange();
			Copied.execCommand("Copy");
		}


	</script>

<body >
	<apex:outputpanel ID="copytext" >
		This text will be copied onto the clipboard when you click the button below.
	</apex:outputpanel>
	
	<TEXTAREA ID="holdtext" STYLE="display:none;">
	</TEXTAREA>
	
	<BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>

</body>	
	
</apex:page>

 

I am not a Javascript expert, which is making this all harder for me. Please help!

 

Thanks,

 

Jeremy