WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Copying to clipboard the contents of a SPAN or DIV, Guillermo, September 12, 2003
     Re:Copying to clipboard the contents of a SPAN or DIV, Erik Arvidsson, September 13, 2003

Subject: Copying to clipboard the contents of a SPAN or DIV From: Guillermo Date: September 12, 2003

I want to be able to copy to the clipboard the contents of a span. I'm using this script I found somewhere, but it copies "undefined" instead of the text I want.

This is the script:

<script language="JavaScript">

   function ClipBoard()
   {
   holdtext.innerText = copytext.innerText;
   Copied = holdtext.createTextRange();
   Copied.execCommand("Copy");
   }
  
</script>

This is where the text I want to copy is. It's an ASP variable. 

<span id="copytext" class="URL"><% =varURL%></span>
<textarea name="textarea" id="holdtext" style="display:none;"></textarea>

And this is the button with the label "Copiar" (Copy):

<input name="btnCopiar" type="button" class="Botones" id="btnCopiar" onClick="ClipBoard();" value="Copiar">

Aparently the script uses a hidden textarea to temporarely store the contents of the SPAN and it copies it to the clipboard.




Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX