Click Copy text compatible with the perfect solution for each browser _javascript tips

Source: Internet
Author: User
Click JS for the copied text. Looking for a long time, because has not been contacted before, completely do not know the compatible IE and standard Dom browser, not only through JS, but also need flash help. Clipboard.swf This is downloaded on the Internet.

IE allows access to the Clipboard. Window.clipboarddata can access
But the standard DOM. Read some articles are said to be hidden with the flash settings. But FLASH10 is not supported.
However, there is a way to do it, solid record, the following methods to support the standard DOM.
Copy Code code as follows:

(function () {
window[' Util '] = {
cache:{},
Gettext:function () {
return Util.CACHE.CLIPBOARD_TEXT;
},
Successhide:function () {
Alert ("Copy the North Sea 365 network recruitment email address!");
},
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=" "height=" "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. You have to add
Copy Code code as follows:

if (window.clipboarddata) {
Window.clipboardData.setData ("Text", pstr);
Util.successhide ();
}
  
This finally enables you to click the copied text and to be compatible with each browser. Remember. The path of the SWF must be right! If the wrong is not to appear hand-shaped, this is characteristic.
Copy Code code as follows:

(function () {
window[' Util '] = {
cache:{},
Gettext:function () {
return Util.CACHE.CLIPBOARD_TEXT;
},
Successhide:function () {
Alert ("Copy the North Sea 365 network 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 (' <object type= ' Application/x-shockwave-flash "Data=" clipboard.swf?gettext=util.gettext&success= Util.successhide "width=" "height=" "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: 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.