jQuery implements copy to pad function

  • 2021-07-18 07:03:15
  • OfStack

The project suddenly needs to use the replication function, under the search on the Internet saw the ZeroClipboard plug-in, easy to use, but there are limitations. The usage is as follows:

1. Refer to jquery, zclip. js, swf files.

demo Address: https://github.com/chaoli920029342/jquery_copy

2. Initialize


<body>
<input type="text" name="text" id="text" value="http://www.baidu.com" />
<a href="javascript:void(0)" rel="external nofollow" id="dynamic"> Duplicate </a>
<script type="text/javascript">
$(document).ready(function(){
 $("#dynamic").zclip({
  path:'ZeroClipboard.swf',
  copy:$('#text').val(),
  beforeCopy:function(){
   //some code
  },
  afterCopy:function(){
   alert($("#text").val());
  }
 });
 //beforeCopy afterCopy  Is optional 
});
</script>
</body>


Note:

1. You need to run localhost on the server

2, js+swf implementation, files need to be introduced at the same time. ZeroClipboard provides a transparent flash for interacting with the cut version. When the "Copy" button on the page is clicked, the required content is passed to Flash, and then the passed content is copied to the clipboard through the copy function of Flash. Ensure that the flash is loaded correctly.

3. Compatible with major browsers


Related articles: