Code field that copies to clipboard when user clicks on the field

Discussion in 'JavaScript' started by Teunel, Jan 12, 2008.

  1. #1
    I'm wondering how to do this:

    I want to show a code field where the users can copy the code to their own site. Photobucket has a very nice way to do this (example)
    When you click on one field, it puts the code in the clipboard.
    I tried looking at their source, but this didn't work:
    
    <input name="txtThumbURLTag2" id="txtThumbURLTag2" class="textBox" type="text" value="VALUE" readonly="readonly" onclick="trackCodeClick(event); copyToClipboard(this);">
    Code (markup):
    Anybody have a clue? I searched around a bit, but all the codes didnt seem to work in Firefox AND Internet Explorer.
     
    Teunel, Jan 12, 2008 IP
  2. sunnyverma1984

    sunnyverma1984 Well-Known Member

    Messages:
    342
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #2
    use window.clipboardData.setData("Text", "mytext")
    replace mytext with your text
     
    sunnyverma1984, Jan 12, 2008 IP