jquery Simple Implementation Click the text box to copy the contents to the Clipboard method _jquery

Source: Internet
Author: User

This article illustrates a simple jquery implementation method of clicking a text box to copy content onto the Clipboard. Share to everyone for your reference, specific as follows:

Click the text box to copy its contents to the Clipboard method function CopyToClipboard (TXT) {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!")
  "); //Click the text box to copy its contents to the Clipboard function Setcopylink () {$ ("#txt_CopyLink"). Val (document.
    URL). focus (function () {$ (this). css ({"Background-color": "#ddd"}). Select ();
  CopyToClipboard ($ ("#txt_CopyLink"). Val ());
  }). blur (function () {$ (this). css ({"Background-color": "#fff"});
});

 }

More interested readers of jquery related content can view the site topics: "JQuery common event usage and skill summary", "jquery form Operation skill Summary", "jquery common Plug-ins and Usage summary", "jquery operation JSON data technique summary", " jquery Extension Tips Summary, jquery table (table) Operation tips Summary, jquery Common Classic effects summary, jquery animation and special effects usage summary and jquery selector Usage Summary

I hope this article will help you with the jquery program design.

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.