Button which copys text to clipboard

Discussion in 'JavaScript' started by Electro-Host, Jun 10, 2010.

  1. #1
    Hello,

    Normally when you go to voucher websites, they make you click on a button to copy the voucher code to your clipboard and whilst clicking, the website will open in a new window.

    I am looking for this sort of Javascript.

    Thanks.
     
    Electro-Host, Jun 10, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
  3. Electro-Host

    Electro-Host Well-Known Member

    Messages:
    321
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Hi,

    I have seen that before but not looking for that sort of thing.

    I want a button where it says Copy or press here and then copy's another piece of text which the user cant see.
     
    Electro-Host, Jun 11, 2010 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    
    
    
    <script tye="text/javascript">
    
    function ClipBoard()
    {
    holdtext.innerText = 'TEXT TO COPY';
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    
    </script>
    
    Code (markup):
     
    stephan2307, Jun 16, 2010 IP
  5. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #5
    execCommand only works for Internet Explorer. If you want a method that works across all browsers, try Zeroclipboard
     
    Cash Nebula, Jun 16, 2010 IP