Click Copy text js. I have been searching for a long time. Since I have never touched on it before, I have no idea whether it is compatible with ie and standard dom browsers. I not only need to use js, but also need the help of flash. Clipboard.swf is downloaded online.
Ie allows access to the clipboard. Window. clipboardData can be accessed
But standard dom. I have read some articles that use flash to hide the settings. However, flash 10 is not supported.
However, there is another method that is feasible, fixed record, the following methods support standard dom.
Copy codeThe Code is as follows:
(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 codeThe Code is as follows:
If (window. clipboardData ){
Window. clipboardData. setData ("Text", pStr );
Util. successHide ();
}
Finally, you can click to copy text and make it compatible with various browsers. Remember. Swf path must be correct! If it is not correct, it is a feature.
Copy codeThe Code is as follows:
(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 copy = document. getElementById ('copy ');
If (window. clipboardData ){
Copy. onclick = function (){
Window. clipboardData. setData ("Text", pStr );
Util. successHide ();
}
} Else {
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 = copy. innerHTML;
Copy. innerHTML = yu + html. join ('');
Util. CACHE. CLIPBOARD_TEXT = pStr;
}
}
}
Util. Copy ('zhaopin @ beihai365.com ');
})();