You often see the effect of clicking a button to copy the contents of an area to the Clipboard. In fact, this function is not difficult to achieve, the core is to use the window Sub-object clipboarddata a method:setData ()
Grammar:
Clipboarddata.setdata (Sdataformat, SData)
Parameters: Sdataformat: The format of the content to be copied; SData: what to copy.
Return value: Copy succeeded return true; Failed returns false.
<script language= "JavaScript" >
function Jianqie (ID)
{var id;
var text=document.all (id). innerText
if (Clipboarddata.setdata ("text", text))
{alert ("Copy succeeded!")}
Else
{alert ("Copy failed!")}
}
</script>
IE JS Code:
Copy CodeThe code is as follows:
<script type= "Text/javascript" >
function CopyUrl2 ()
{
var Url2=document.getelementbyid ("Biao1");
Url2.select (); Select Object
Document.execcommand ("Copy"); Perform a browser copy command
Alert ("Copied well, can be glued. ");
}
</script>
<textarea cols= "rows=" id= "Biao1" > user-defined code area </textarea>
<input type= "button" onclick= "CopyUrl2 ()" value= "click Copy Code"/>
Chrome JS Code:
Copy CodeThe code is as follows:
<script src= "Http://www.weicaiyun.com/assets/js/copy/ZeroClipboard.js" ></script>
<script type= "Text/javascript" >
var clip = new Zeroclipboard.client ();
Clip.sethandcursor (TRUE);
Clip.settext (' copy content ');
Clip.glue (' button ');
</script>
<input type= "button" id= "button" value= "click Copy Code"/>
http://zeroclipboard.org/#demo//zeroclipboard
http://blog.csdn.net/skyboxgogo/article/details/8768683 Detailed-----
JS for browser-compatible copy function