Home > Web Front-end > JS Tutorial > body text

The perfect solution to copy text with one click, compatible with all browsers_javascript skills

WBOY
Release: 2016-05-16 17:30:00
Original
1257 people have browsed it

Click the js to copy the text. I have been looking for it for a long time. Since I have never been in contact with it before, I have no idea that it is compatible with IE and standard DOM browsers. It not only requires js, but also requires the help of flash. clipboard.swf is available for download online.

ie allows access to the clipboard. window.clipboardData has access to
but is standard dom. I read some articles that all use flash settings to hide. But flash10 does not support it.
However, there is another method that is feasible. Just record it. The following method supports standard DOM.

Copy code Code As follows:

(function () {
window['Util'] = {
CACHE:{},
getText : function(){
return Util. CACHE.CLIPBOARD_TEXT;
},
successHide : function(){
alert("Copy Beihai 365 recruitment email address!");
},
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. You must also add
Copy code The code is as follows:

if (window.clipboardData) {
window.clipboardData.setData("Text",pStr);
Util.successHide();
}
 
Finally, this can realize single-click copying of text and is compatible with all browsers device. remember. The path of swf must be correct! If it is wrong, the hand shape will not appear. This is a characteristic.
Copy code The code is as follows:

(function () {
window['Util '] = {
CACHE:{},
getText : function(){
return Util.CACHE.CLIPBOARD_TEXT;
},
successHide : function(){
alert( "Copy the Beihai 365 recruitment email address!");
},
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('< ;param name="allowFullScreen" value="true" />');
html.push('');
html. push('
');
var yu=copy.innerHTML;
copy.innerHTML=yu html.join('');
Util.CACHE.CLIPBOARD_TEXT = pStr;
}
}
}
Util.Copy('zhaopin@beihai365.com ');
})();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template