Home > Web Front-end > JS Tutorial > body text

Code sharing on how JavaScript uses ZeroClipboard to operate the clipboard

黄舟
Release: 2017-05-14 10:14:22
Original
1509 people have browsed it

This article mainly introduces the relevant information of JavaScript using ZeroClipboard to operate the clipboard. It has certain reference value. Interested friends can For reference

1. ZeroClipboard download address

provides you with a detailed download address of ZeroClipboard:

Zero Clipboard open source JavaScript+flash copy library class

Copy and paste website content based on ZeroClipboardJS special effectsSource code

zeroclipboard Copy to cut implemented with js and flash Board file

2. Add jsreference

<script src="../Assets/js/jquery-1.8.3.min.js"></script>
 <script src="../Assets/js/ZeroClipboard/ZeroClipboard.js"></script>
Copy after login

3.Initialize plug-in

$(function () {
   InitCopyToClipboard(&#39;btnCopyToClipBoard&#39;);
 });
//将内容复制到剪切板
function InitCopyToClipboard(btnId) {
ZeroClipboard.setMoviePath("../Assets/js/ZeroClipboard/ZeroClipboard.swf"); //设置flash文件在项目中的位置 
var clip = new ZeroClipboard.Client(); // 新建一个对象

clip.setHandCursor(true);
clip.addEventListener(&#39;onmouseup&#39;, function (client) { //创建监听 
 // 可以在这儿写一个方法处理相应的事件逻辑
 clip.setText(&#39;要复制到剪切板中的内容&#39;); 
});
clip.glue(btnId); //将flash覆盖至指定ID的DOM上


//窗口大小发生变化时从新将flash覆盖至制定的id上,否则位置不对应导致点击时没反应
bind(window, "resize", function () {
  clip.reposition();
});
return false;
}

/************************************ 
* 添加事件绑定 
* @param obj : 要绑定事件的元素 
* @param type : 事件名称。不加 "on". 如 : "click" 而不是 "onclick". 
* @param fn : 事件处理函数 
************************************/
function bind(obj, type, fn) {
if (obj.attachEvent) {
obj[&#39;e&#39; + type + fn] = fn;
obj[type + fn] = function () { obj[&#39;e&#39; + type + fn](window.event); }
obj.attachEvent(&#39;on&#39; + type, obj[type + fn]);
} else
obj.addEventListener(type, fn, false);
}
Copy after login

The above is the detailed content of Code sharing on how JavaScript uses ZeroClipboard to operate the clipboard. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template