In JS there is a clipboarddata.setdata (Sdataformat, sData) function that can be implemented
The code is as follows |
Copy Code |
Clipboarddata.setdata ("text", www.111cn.net) <a href= "#" Onclick=javascript:clipboarddata.setdata ("text", "Www.111cn.net") > Clicking on the current link text indicates that the content has been copied to the local clipboard, and the definition can be displayed simply by "Ctrl" + "V" </a> |
How to get "Copy selection", which requires the use of the Document.selection.createRange () method
The code is as follows |
Copy Code |
<script type= "Text/javascript" > Document.body.oncopy=function () { Event.returnvalue=false; var t=document.selection.createrange (). text; var s= "About clicking the button to copy content to the Clipboard's original content address:" +LOCATION.HREF; Clipboarddata.setdata (' Text ', t+ ' rnrn ' +s+ ' rn '); } </script> |
The above method can be used in ie,ff but sometimes in some browsers will not be compatible oh, let me introduce a better solution
Zero Clipboard, using this JS library can support the use of Flash 10 implementation to copy to the Clipboard. The idea is to overwrite a DOM element such as a button or div on a transparent flash (invisible to the user), and when clicked on the DOM, it actually clicks on Flash, which accesses the Flash clipboard.
The code is as follows |
Copy Code |
<title>zero Clipboard test</title> <script type= "Text/javascript" src= "Zeroclipboard.js" ></script> <script language= "JavaScript" > var clip = null; function $ (ID) {return document.getElementById (ID);} function init () { Clip = new Zeroclipboard.client (); Clip.sethandcursor (TRUE); Clip.addeventlistener (' MouseOver ', function (client) { Update the text on mouse over Clip.settext ($ (' Fe_text '). Value); });
Clip.addeventlistener (' Complete ', function (client, text) { Debugstr ("Copied Text to Clipboard:" + text); Alert ("The address has been copied and you can paste it using CTRL + V.") "); }); Clip.glue (' Clip_button ', ' Clip_container '); } </script> <body onload= "init ()" > <input id= "Fe_text" cols=50 rows=5 value= Copy content Text 1 > <span id= "Clip_container" ><span id= "Clip_button" ><b> replication </b></span></span> </body> |