Results 1 to 10 of 10

Thread: Copy Textarea content to clipboard

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Copy Textarea content to clipboard

    For some reason I'm having a hard time finding this. I'm looking for a script that would allow users to click in a textarea box and it would automatically copy to clipboard whatever is in the box. Preferably it would say "copied" too so that the user knows that it was copied. (Just like photobucket) All the scripts I seem to find require a button/link or don't work in firefox.

    Is there a script that works in both IE and Firefox? Any help would be appreciated. Thanks soooo much!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not aware of a script that will copy to the clipboard. Might be possible using ActiveX in IE only.
    But you can do a select all operation automatically, then have the user copy himself. You can find this select all script in the DD library I believe.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Yeah all the scripts i found have some button or a link that says "copy" and then the user clicks it and it copies whatever is in the textarea. But, I saw that photobucket has it so you just click in the textbox and it copies the data automatically...Anyone know how this is done?

    Some of the scripts I have found don't even work in firefox and only work in IE so I don't know how photobucket does it...

  4. #4
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hey all,

    So I found this:

    Code:
    <script language="javascript">
    
    
    function copy(inElement) {
      if (inElement.createTextRange) {
        var range = inElement.createTextRange();
        if (range)
          range.execCommand('Copy');
      } else {
        var flashcopier = 'flashcopier';
        if(!document.getElementById(flashcopier)) {
          var divholder = document.createElement('div');
          divholder.id = flashcopier;
          document.body.appendChild(divholder);
        }
        document.getElementById(flashcopier).innerHTML = '';
        var divinfo = '<embed src="_clipboard.swf" FlashVars="clipboard='+encodeURIComponent(inElement.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
        document.getElementById(flashcopier).innerHTML = divinfo;
      }
    }
    
    </script>
    
    
    <form name="formtocopy" action="" >
    <textarea name="texttocopy" disabled="disabled">
    A whole bunch of text here that will be copied.
    </textarea>
    <br>
    <a href="javascript:copy(document.formtocopy.texttocopy);">Copy the Text!</a>
    </form>
    This apparently does work across diff browsers and it's not exactly what i wanted but it will do. Anyway, is there a way i can write "copied..." right next to the button when it is clicked. indicating to the user that it has been copied). I know this is probably a dumb question but I don't know how to do that.

  5. #5
    Join Date
    Jun 2007
    Posts
    34
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I have that programmed well (not pulling from the text area, doing it hardcode with PHP) but am sure you can do it just like photobucket. In fact, I need to update my code to make that much nicer feature, improve the language in my clipboard copy. I have popup alert() working too. Would prefer the CSS thing that is done by Photobucket. Perhaps someone can do that and report back to me and I'll implement it in my website.

    http://www.jeffothy.com/weblog/clipboard-copy/

    I discovered it from reading blog of guy who created 2Prong. That blog is not working a the moment, not sure why. "webchicanery.com"

    (too bad nobody answers my questions in this forum .... hint)

  6. #6
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    yeah i hear ya. the code on that jeff site was good but my problem with that was that there was no indication it "copied" to the user. otherwise it works perfectly. anyway, i ended up just finding a script that just selects all and the user will have to copy and paste.

  7. #7
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,486
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    unless you want it in Flash, I don't see any other way except user interaction....
    {CWoT - Riddle } {OSTU - Psycho} {Invasion - Team}
    Follow Me on Twitter: @Negative_Chaos
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  8. #8
    Join Date
    Jun 2007
    Posts
    34
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I'm surprised you can't get it to work by just clicking in the textarea? Isn't there a javascript that would detect such and you can use to trigger the clipboard copy JS? I was using <a> tag and when someone clicks on it he clipboard copy would occur, and the alert() box would tell user that info was just copied to their clipboard.

    If anyone knows of JS that can detect when user clicks into a Text Area, please post in this thread. I havn't done google search.

    FYI, I am using Dynamic Drive FormLimiter script, by Twey, but it seems to have disappeared? It monitors the text area input size. Perhaps you can check that out to see how it's programmed, maybe it will have a trick you can use?

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    onFocus="....." will activate when you click into a form field.
    That link is interesting, though reliant upon flash.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Apr 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hey guys, i came across this thread while searching the net for the same thing but what i want to accomplish is to copy to the clipboard, using the above script, the webpage current URL. is that possible? i've tried to play with the form above location.href etc' but with no luck.

    thanks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •