Search code examples
jqueryzclip

zClip is not working


This is Updated Code for Clip Copy

 <script src="jquery-1.8.0.min.js" type="text/javascript"></script>
 <script type="text/javascript" src="http://www.steamdev.com/zclip/js/jquery.zclip.min.js"></script>

in body section :

  <div>
    <input type="text" id="txtEmbedLink" />
    <button id="btnCopyClipboard">
        copy</button>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $('#btnCopyClipboard').zclip({
            path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
            copy: $('#txtEmbedLink').val(),
            beforeCopy: function () {
                alert('before copy');
            },
            copy: function () {
                alert('copy');
                return $('#txtEmbedLink').val();
                            },
            afterCopy: function () {
                alert('after copy');
            }
        });
    });

the problem is when I click on button, just beforeCopy runs correctly, nothing after Copy, (guess the problem is Copy function: alert command in Copy runs correctly)


Solution

  • I had found the solution for you, modify your code as the jsfiddle is different with the local code

    attached with jsfiddle http://jsfiddle.net/sxeCM/101/

    the main issue is the dynamic value that already mention in the web, and put it in dom ready instead of button click

    $(document).ready(function () {
        $('#btnCopyClipboard').zclip({
            path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf', //this remain as the one you had
            copy:function(){return $('#txtEmbedLink').val();} //change this to be the clientid
        });
    });
    

    Updated answer:

    check this http://jsfiddle.net/sxeCM/102/

      $(document).ready(function () {
            $('#btnCopyClipboard').zclip({
                path: 'http://www.steamdev.com/zclip/js/ZeroClipboard.swf',
                copy:function(){return $('#txtEmbedLink').val();},
                beforeCopy: function () {
                  console.log("test");
                },
                afterCopy: function () {
                    alert('after copy');
                }
            });
        });
    

    as tested in this jsfiddle, I figure out that alert in beforecopy eventually cause an unknow glitch where the zclip did not copy the text input, instead of using alert, I change it to console.log, which show that the copy work, so if you want to test, why don't replace your alert with console.log("before copy")? by the way, the path should remain as the original path you had, don't use the sample path