Click to copy the JS code instance _javascript tips

Source: Internet
Author: User

Copy Code code as follows:

function Copy_clip () {
var url = $ ("#back_info"). html (); Content that needs to be replicated
var txt = url.substring (Url.indexof (":") + 1, url.length);
if (window.clipboarddata) {
Window.clipboardData.clearData ();
Window.clipboardData.setData ("Text", txt);
Alert (' Congratulations, copy success! ');
else if (navigator.userAgent.indexOf ("Opera")!=-1) {
window.location = txt;
else if (Window.netscape) {
try {
Netscape.security.PrivilegeManager.enablePrivilege ("Universalxpconnect");
catch (e) {
Alert ("Your Firefox security restrictions restrict your clipboard operations, please enter ' About:config ' in the address bar of the new window and find ' Signed.applets.codebase_principal_ Support ' set to true ');
return false;
}
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);

}
}

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.