Home>
//Click the text box to copy its content to the clipboard method
function copytoclipboard (txt) {
  if (window.clipboarddata) {
    window.clipboarddata.cleardata ();
    window.clipboarddata.setdata ("text", txt);
    alert ("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 the browser! \ nPlease enter" about:config "in the browser address bar and press Enter \ n and 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 ("Successfully copied to the clipboard!");
  }
}
//click the text box to copy its content 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"});
  });
}
  • Previous jQuery implements click box selection or cancel CheckBox method
  • Next Detailed usage of XUtils3 framework in Android (1)