JS will make content copy to the Clipboard sample code _javascript Tips

Source: Internet
Author: User
Copy Code code as follows:

function CopyText () {

Copy content
var txt = document.getElementById ("Table2"). rows[1].cells[0].innerhtml;

Remove spaces
TXT = txt.replace (//, "");

Remove Line Wrap
txt = txt.replace (/<br><br>/, "");
if (window.clipboarddata) {
Window.clipboardData.clearData ();
Window.clipboardData.setData ("Text", txt);
Alert ("has been successfully copied to the Clipboard!") ");
}else if (navigator.userAgent.indexOf ("Opera")!=-1) {
window.location = txt;
}else if (window.netscape) {
try {
Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");
catch (e) {
Alert ("Rejected by browser!") \ nplease type ' About:config ' in the browser address bar and enter \ n then set ' Signed.applets.codebase_principal_support ' to ' true ');
}
var clip = components.classes[' @mozilla. Org/widget/clipboard;1 '].createinstance ( Components.interfaces.nsIClipboard);
if (!clip) return;
var trans = components.classes[' @mozilla. Org/widget/transferable;1 '].createinstance ( Components.interfaces.nsITransferable);
if (!trans) return;
Trans.adddataflavor (' Text/unicode ');
var str = new Object ();
var len = new Object ();
var str = components.classes["@mozilla. Org/supports-string;1"].createinstance ( Components.interfaces.nsISupportsString);
var copytext = txt;
Str.data = CopyText;
Trans.settransferdata ("Text/unicode", str, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip) return false;
Clip.setdata (trans, NULL, Clipid.kglobalclipboard);
Alert ("has been successfully copied to the Clipboard!") ");
}
}

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.