Page 1 of 1
Is there a way...
Posted: Wed Oct 08, 2003 1:16 am
by 3.14
I have a php script which generates a code which is passed into a variable.
From this, can I create a button/hyperlink to automatically select the outputted code and copy it to clipboard? Or just select it when the button is pressed. I know it's lazy since all you have to do is select the damn thing, but this ensures no possible error due to not selecting the entire code.
Any ideas???

Posted: Wed Oct 08, 2003 3:26 am
by Nay
This is more of client side actually. Use this function:
Code: Select all
<script language="javascript" type="text/javascript">
function ClipBoard()
{
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("Copy");
}
</script>
More here:
http://www.htmlgoodies.com/beyond/clipboard.html
-Nay
Posted: Wed Oct 08, 2003 3:06 pm
by m3rajk
nice, now if there's a way to do it that's not only in ie i actually have a link i'd love to make copyable...
Posted: Wed Oct 08, 2003 4:18 pm
by scorphus
m3rajk wrote:nice, now if there's a way to do it that's not only in ie i actually have a link i'd love to make copyable...
I don't think it's possible for example perform this thing in Mozilla. Clipboard is a Windows-specific functionality and copying data to it is not related to HTML. This is another 'ie added function', like you said.
Regards,
Scorphus.
Posted: Thu Oct 09, 2003 6:38 pm
by Vincent Puglia
Hi,
could you be a bit more specific about the environment in question? eg: html code you are working with.
Vinny
Posted: Thu Oct 09, 2003 6:40 pm
by 3.14
Thanks for the help so far... I love you guys!
I have the following:
Code: Select all
<?php
//display the code with the remainding digits padded with X's
echo '<span ID="copytext" STYLE="height:100;width:150;" style="color: #003366;"><font face="Arial" size="4"><B>CODE IS "' . str_pad($code_so_far, 8, "X") . '"<B></font></span>';
// button for copying the code above to clipboard
?><TEXTAREA ID="holdtext" STYLE="display:none;">
</TEXTAREA>
<BUTTON onClick="ClipBoard();">Copy Code</BUTTON><?
?>
Now as you can see, all works fine and dandy... except it selects "CODE IS ANDHDTSX" and all I want is the "ANDHDTSX" (ANDHDTSX is for example purposes only).
Now I tried adding a span within a span to limit the selection to the str_pad($code_so_far, 8, "X") section but php didn't like that and I get a blank page. Yay.
So... lets play who can find a way around this loophole! First person to win gets a free lunchbox!

Posted: Thu Oct 09, 2003 6:59 pm
by Vincent Puglia
And where is the text supposed to go (besides the ClipBoard, which is a Windows thingy and not an IE one)
Vinny