Page 1 of 1

Copy text to clipboard when clicking a link

Posted: Mon Oct 27, 2003 2:34 am
by vigge89
I need a script that, when a link is clicked, copies a text echoed by a php scipt. I dont know javascript, so i have no idea, but it would look something like this:

php has echoed a string in the script which says what to copy => user clicks the link => javascript copies the string from the php-script into clipboard => a popup pops up saying that the text is copied.

Posted: Mon Oct 27, 2003 2:36 am
by m3rajk
hey! i tried that not too long ago. try searching for me. there's the one i did on that, and the answeri got, and a diff thread i commented in., both of which should be what you are looking for. i'll tyr to find them to help you

Posted: Mon Oct 27, 2003 2:37 am
by vigge89
m3rajk wrote:hey! i tried that not too long ago. try searching for me. there's the one i did on that, and the answeri got, and a diff thread i commented in., both of which should be what you are looking for. i'll tyr to find them to help you
thanks :D

Posted: Mon Oct 27, 2003 2:56 am
by m3rajk
my post: viewtopic.php?t=13511
what i hacked up in that try: viewtopic.php?t=13378

Posted: Mon Oct 27, 2003 2:57 am
by vigge89
thx, ill take a look at them now :)

Posted: Mon Oct 27, 2003 3:01 am
by vigge89
hmmmmm, i didn't found it there so ill ask it here:
is it possible to make it crossbrowser?

Posted: Mon Oct 27, 2003 7:53 am
by m3rajk
as a client side function it can't be done for two reasons:

1: javascript has no way to copy. only M$IE's version (jscript) which has a s**tload of non-standards, does. this willONLY WORK IN M$IE 5.0 (maybe 5.5) AND HIGHER

2: the aformentined jscript will only work with a form, when the button get the info from a textarea or text field

Posted: Mon Oct 27, 2003 9:06 am
by vigge89
ok, then i just skip the copy to clipboard prt onmy site :?

Posted: Mon Oct 27, 2003 11:24 am
by m3rajk
lol. that was my reaction too. would you like to see what i wrote figuring that i'll play with it after i get the site online to see if i can get it working properly?

maybe working together we can find something that'll get around M$SE's screwball antics and do what we want.

Posted: Mon Oct 27, 2003 11:40 am
by vigge89
m3rajk wrote:lol. that was my reaction too. would you like to see what i wrote figuring that i'll play with it after i get the site online to see if i can get it working properly?

maybe working together we can find something that'll get around M$SE's screwball antics and do what we want.
well, ok, but i cant help you on the jscript coding, but ill help ya with anything else, just ask ;)

Posted: Mon Oct 27, 2003 12:45 pm
by moerlien
Here's a link to a free code script that might be useful. They are working on a beta version that will be cross browser.

Posted: Mon Oct 27, 2003 6:23 pm
by m3rajk
vigge89 wrote:
m3rajk wrote:lol. that was my reaction too. would you like to see what i wrote figuring that i'll play with it after i get the site online to see if i can get it working properly?

maybe working together we can find something that'll get around M$SE's screwball antics and do what we want.
well, ok, but i cant help you on the jscript coding, but ill help ya with anything else, just ask ;)
lol.

here's what i have:

Code: Select all

<script language="Javascript">
function toClipboard(){
  var text="/* text to copy goes here */";
  var copyText=text.createTextRange();
  
  if(confirm("Do you want to copy the link /* here i double the copy text */ to your clipboard?\n(this only works for M\$IE");){
    copyText.execCommand("Copy");
    alert("If using M\$IE, then you have just copied the link, /* again i give the code to be copied */ to your clipboard.");
  }
}
</script>

Posted: Tue Oct 28, 2003 2:20 am
by vigge89
what does that smilie do there? Nah, j/k it's ; ) ;)
Ok that works on M$IE, but not on NS or anyone else (yet :? ).