Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
function test() {

        ZeroClipboard.setMoviePath('zeroclipboard/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');

       }


My aspx code

ASP.NET
<<blockquote class="FQ"><div class="FQA">Quote:</div>body>
    <form id="form1" runat="server">
    <div>
    <textarea name="box-content" id="box-content" rows="5" cols="70">
  This is a test text 
</textarea>
<br /><br />
<p><input type="button" id="copy" name="copy" value="Copy to Clipboard" onclick="javascript:test();" /></p>

<p>
<%--<asp:Button ID="copy" runat="server" Text="Copy to Clipboard" OnClientClick="javascript:test();" />--%>
</p>
    </div>
    </form>
</body</blockquote>>
Posted

1 solution

You have invoked function test on button click. There the initialization of the ZeroClipboard will take place thats why it require second click to activate better initialize ZeroClipboard at on load

JavaScript
window.onload = function MyFunction() {
                var sss = "my Name";
                var clip = clip = new ZeroClipboard.Client();
                clip.setText(sss);
                clip.glue('d_clip_button');
            }


or use

JavaScript
var clip = clip = new ZeroClipboard.Client();
            window.onload = function MyFunction() {
                var sss = "my Name";                
                clip.setText(sss);
                clip.glue('d_clip_button');
            }

            clip.addEventListener('onMouseDown', function (client) {
                 //alert("mouse over");
            });
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900