Click Copy text to be compatible with the perfect solution for various browsers _ javascript tips

Source: Internet
Author: User
I have been searching for the js that I have clicked to copy text 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, next we will share with you the specific implementation method. 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.

The 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 ('');
Html. push ('');
Html. push ('');
Html. push ('');
Html. push ('');
Html. push ('');
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

The 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.

The 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 ('');
Html. push ('');
Html. push ('');
Html. push ('');
Html. push ('');
Html. push ('');
Var yu = copy. innerHTML;
Copy. innerHTML = yu + html. join ('');
Util. CACHE. CLIPBOARD_TEXT = pStr;
}
}
}
Util. Copy ('zhaopin @ beihai365.com ');
})();

Related Article

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: info-contact@alibabacloud.com 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.