Click the perfect solution to copy text compatible with various browsers

Source: Internet
Author: User

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 ');
})();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.