使用ZeroClipboard解决跨浏览器复制到剪贴板的问题

<!DOCTYPE html>
<html>
<head> 
<script type="text/javascript" src="jquery.js"></script>    
<script type="text/javascript" src="ZeroClipboard.min.js"></script>    
<script>   ZeroClipboard.setDefaults( { moviePath: 'ZeroClipboard.swf' } );  </script> 
</head>
<body>
<div id="d_clip_button" data-clipboard-target="key">Copy To Clipboard</div>
<input name="s" value="13123" id="key">
</body>
</html>
 <script>   
 $(function(){
   var clip = new ZeroClipboard( $('#d_clip_button') );        
  clip.on( 'complete', function(client, args) {            
      alert("Copied text to clipboard: " + args.text );       
  } );      
 })
 </script>

注:如果你是循环出来的列表,可以将id = d_clip_button  改成 class = d_clip_button

data-clipboard-target = "key"是获取id=key的value,所以循环的话要在key后加个id号,以免重复

文件:zeroclipboard.mis.js/zeroclipboard.swf放在同一域名下

文件下载地址:https://github.com/jonrohan/ZeroClipboard/tree/gh-pages

使用方法地址:https://github.com/jonrohan/ZeroClipboard/blob/master/docs/instructions.md#a-note-on-the-allowscriptaccess-option

我出现的一些错误:

uncaught exception: Error in Actionscript. Use a try/catch block to find error.

anwser:Change the swf_url config param from " https://site.com/path/to/swfstore.swf" to just "//site.com/path/to/swfstore.swf" - it will automatically choose the correct protocol and flashplayer will allow data to be shared between http and https.



你可能感兴趣的:(使用ZeroClipboard解决跨浏览器复制到剪贴板的问题)