ZeroClipboard - copy text to clipboard not working

user2580777 picture user2580777 · Jul 19, 2013 · Viewed 9.4k times · Source

I want to try this DEMO to copy text to the clipboard by using ZeroClipboard. I have one local folder with the index.html, ZeroClipboard.js and ZeroClipboard.swf int it. but it does not work:

<html>
<body>
    <script type="text/javascript" src="ZeroClipboard.js"></script>
    <script type="text/javascript">
        //set path
        ZeroClipboard.setMoviePath('ZeroClipboard.swf');
        //create client
        var clip = new ZeroClipboard.Client();
        //event
        clip.addEventListener('mousedown', function () {
            clip.setText(document.getElementById('box-content').value);
        });
        clip.addEventListener('complete', function (client, text) {
            alert('copied: ' + text);
        });
        //glue it to the button
        clip.glue('copy');
    </script>

    <textarea name="box-content" id="box-content" rows="5" cols="70">
        The David Walsh Blog is the best blog around!  MooTools FTW!
    </textarea>
    <br />
    <br />
    <p>
        <input type="button" id="copy" name="copy" value="Copy to Clipboard" />
    </p>
</body>
</html>

Answer

David picture David · Jul 24, 2013

You have to run a server. Because the link to you site must contain http or https. It's because of adobe flash's security settings