Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zeroclipboard fire click event via jquery

ZeroClipboard is a javascript + flash script that allows the browser to put text into the clipboard, it puts a transparent flash over the selected element , and when you click it you can insert text into the clipboard, this works, no problem, but i want to make it automatic. Onload put a string in the clipboard, for the user to be able to paste it latter. Some code main.js

$('document').ready(function() {
ZeroClipboard.setMoviePath("http://url/to/ZeroClipboard.swf");
  var clip=new ZeroClipboard.Client();
 clip.on( 'load', function(client) {
   clip.glue('#redirlink');
} );
});

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr" >
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="main.js"></script>

    <title>TEST</title>
  </head>
  <body>


      <div >
     <a  id="redirlink" data-clipboard-text="abcd" href="http://alabala.com" >Click HERE</a>

    </div>

  </body>
</html>

ok now the question is how can i simulate a click event on the the zeroClipboard puts? i have tried with , $('#obkect_id").click(); it doesn't work (the event fires, but it has no effect on the clipboard, but when i click with the mouse, it works). Is there any way i can achieve that?

like image 966
Nikola Avatar asked Jan 26 '26 08:01

Nikola


1 Answers

The newest versions of ZeroClipboard have done away with Client(). Hence the code changes a bit too. Download the latest version from Github here

Also then say you want to update/put some string when page/element loads. Say on clicking the 'element' having id '#id', the clipboard needs to be loaded with some text

<script>
var str = 'Some text';
$('element').attr('data-clipboard-text','str');
ZeroClipboard.setDefaults({moviePath:'http://...../ZeroClipboard.swf'});
var clip = new ZeroClipboard($('#id'));
clip.on('complete',function(client, args){
alert('Copied');
});
</script>

Hope this helps

like image 126
Navin Nagpal Avatar answered Jan 27 '26 22:01

Navin Nagpal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!