We all know that using the general method, we cannot copy the content across browsers, and there is no way to copy the content to the clipboard under ff, next, I will introduce a Zero Clipboard plug-in to implement cross-Browser IE copying content to the Clipboard. For more information, see.
Implementation principle of Zero Clipboard
Zero Clipboard uses transparent Flash to float the copy button. In this way, you can click not a button but Flash, so that you can pass the required content into Flash, then, copy the input content to the Clipboard through the Flash copy function.
How to install Zero Clipboard
In fact, it is not the installation, that is, preparations before use.
First, download the compressed Zero Clipboard package, decompress the package, and put the two files in the folder: ZeroClipboard. js and zeroclipboard.swf into your project.Carrier address: http://file.bKjia. c0m/download/2013/06/03/zeroclipboard-1.0.7.tar.gz
The Code is as follows: |
Copy code |
<Script type = "text/javascript" src = "ZeroClipboard. js"> </script> |
Note: The preceding ZeroClipboard. js and ZeroClipboard.swf must be placed in the same path. If the path is not the same, use ZeroClipboard. setMoviePath ("Flash path ");
To set the zeroclipboard.swf address
The Code is as follows: |
Copy code |
Zero Clipboard for simple cross-browser Replication Var clip = new ZeroClipboard. Client (); // create an object Clip. setHandCursor (true); // set the mouse to the Hand Type Clip. setText ("Haha"); // set the text to be copied. // Register a button with the parameter id. Click this button to copy it. // This button is not necessarily an input button or other DOM elements. Clip. glue ("copy-botton ");// |
And the last sentence cannot be changed, so that the basic function is implemented, click the button to copy the set text. You may have noticed that the text to be copied is fixed. What if you want to change it dynamically, such as copying the content in an input box?