Domanda

No idea why my below is not working on single click, It requires twice click to get copied.

<html>
<body>
<script type="text/javascript" src="JQuery.js"></script>
<script type="text/javascript" src="zClip.js"></script>

<textarea id="fe_text" cols="50" rows="5"></textarea>

<input type="button" id="copyTxt" name="copyTxt" value="Copy Div to Clipboard" />

    <script language="JavaScript">
    $(document).ready(function()
    {       
        $('#copyTxt').click(function()
            {
               //alert($('#fe_text').val());
               $(this).zclip(
               {
                   path: 'ZeroClipboard.swf',
                   copy: $('#fe_text').val(),
                   afterCopy: function()
                   {
                       console.log($('#fe_text').val() + " was copied to clipboard");
                   }
               });
            });
    });


    </script>
</body>
</html>

Please suggest, what could be the reason

Thanks.

È stato utile?

Soluzione

Your code sets up zclip to start watching for clicks, after it's clicked once.

$(document).ready(function()
{       
    //$('#copyTxt').click(function()
    //    {
           //alert($('#fe_text').val());
           $('#copyTxt').zclip(
           {
               path: 'ZeroClipboard.swf',
               copy: function(){ return $('#fe_text').val(); },
               afterCopy: function()
               {
                   console.log($('#fe_text').val() + " was copied to clipboard");
               }
           });
    //    });
});

If you look at their documentation, it shows the zclip plugin being called directly inside $(document).ready.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top