This article collects several common summaries and shares about clicking Copy text to clipboard code. We usually use clipboardData to copy text to the cut version in ie. setData is used for instances. For more information, see.
IE browser replication method
Example 1
The Code is as follows: |
Copy code |
// Text copy CopyText = function (str ){ If (browerKernel. isIE ()){ ClipboardData. setData ('text', str ); Alert ("the site link has been copied to your clipboard. n you can press CTRL + V to paste "); } Else { Prompt ("your browser does not support automatic replication. Press CTRL + C to manually copy:", str ); } }; |
Example 2
Click the copy button code:
The Code is as follows: |
Copy code |
<SCRIPT language = JavaScript> <! -- Function MM_goToURL () {// v3.0 Var I, args = MM_goToURL.arguments; document. MM_returnValue = false; For (I = 0; I <(args. length-1); I + = 2) eval (args [I] + ". location = '"+ args [I + 1] + "'"); } Function JM_cc (ob ){ Var obj = MM_findObj (ob); if (obj ){ Obj.select({%js%obj.createtextrange(%%%js.exe cCommand ("Copy ");} } Function MM_findObj (n, d) {// v4.0 Var p, I, x; if (! D) d = document; if (p = n. indexOf ("? ")> 0 & parent. frames. length ){ D=parent.frames[n.substring(p%1%].doc ument; n = n. substring (0, p );} If (! (X = d [n]) & d. all) x = d. all [n]; for (I = 0 ;! X & I <d. forms. length; I ++) x = d. forms [I] [n]; For (I = 0 ;! X & d. layers & I <d. layers. length; I ++) xw.mm_findobj(n,d.layers+ I }.doc ument ); If (! X & document. getElementById) x = document. getElementById (n); return x; } // --> </SCRIPT> <INPUT name = Button onclick = "JM_cc ('js _ 1')" type = button value = copy to clipboard> <BR> <FORM action = "" method = post name = form1> <Div align = "center"> <TEXTAREA cols = 70 name = js_1 rows = 10 wrap = VIRTUAL> content to be copied </textarea> </Div> </Form> |
Example 3
The Code is as follows: |
Copy code |
(Function (){ Window ['util'] = { CACHE :{}, GetText: function (){ Return Util. CACHE. CLIPBOARD_TEXT; }, SuccessHide: function (){ Alert ("copy the recruitment email address of Beihai 365! "); }, Copy: function (pStr, hasReturn, isdo ){ Var html = []; Html. push ('<object type = "application/x-shockwave-flash" data = "clipboard.swf? Gettext = Util. getText & success = Util. successHide "width =" 50 "height =" 40 "style =" position: relative; top: 11px; left:-50px; "id =" ff_clipboard_swf "> '); Html. push ('<param name = "quality" value = "high"/> '); Html. push ('<param name = "allowScriptAccess" value = "sameDomain"/> '); Html. push ('<param name = "allowFullScreen" value = "true"/> '); Html. push ('<param name = "wmode" value = "transparent"/> '); Html. push ('</object> '); Var yu = document. getElementById ('copy'). innerHTML; Document. getElementById ('copy'). innerHTML = yu + html. join (''); Util. CACHE. CLIPBOARD_TEXT = pStr; } } Util. Copy ('zhaopin @ beihai365.com '); })(); If you want to be compatible with ie. Add Copy the Code as follows: If (window. clipboardData ){ Window. clipboardData. setData ("Text", pStr ); Util. successHide (); }
|