Funkcionalnosć toś togo sedła se pśez wótwardowańske źěła wobgranicujo, kótarež maju wašo dožywjenje pólěpšyś. Jolic nastawk waš problem njerozwězujo a cośo pšašanje stajiś, wobrośćo se na našo zgromoźeństwo pomocy, kótarež na to caka, wam na @FirefoxSupport na Twitter a /r/firefox na Reddit pomagaś.

Pomoc pśepytaś

Glědajśo se wobšudy pomocy. Njenapominajomy was nigda, telefonowy numer zawołaś, SMS pósłaś abo wósobinske informacije pśeraźiś. Pšosym dajśo suspektnu aktiwitu z pomocu nastajenja „Znjewužywanje k wěsći daś“ k wěsći.

Dalšne informacije

I am in need for a js snippet for client side copy paste functionality in firefox without any flash plugins

more options

Right now I am using the below snippet for achieving copy paste functionality on the client site..

if (window.netscape) {

   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   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 = maintext;
   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);

}

But recently came to notice that netscape.security.PrivilegeManager is no longer supported as a security concern. Is there any alternative approach to achieve this??

Thanks,

Right now I am using the below snippet for achieving copy paste functionality on the client site.. if (window.netscape) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); 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 = maintext; 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); } But recently came to notice that netscape.security.PrivilegeManager is no longer supported as a security concern. Is there any alternative approach to achieve this?? Thanks,

Wšykne wótegrona (4)

more options

Hi

This sounds more like a web development query that an issue with the Firefox web browser.

I recommend you ask at Stack Overflow where one of the experts there should be able to help you.

more options

Hi ykonathala, what problem are you trying to solve?

Do you think users don't know how to use the Copy feature on their own and need you to do it for them?

What method are you using in Google Chrome? Perhaps Firefox has adopted a similar API by now.

more options

We have some fields on the multi-select box where I show the value with label and the value of that options will have a tokens and that should be copied to clip board, when I click on a copy button, other wise users cannot get that value associated to each option of that multi-select box. So to achieve this I am using the above pasted code in the onclick of the copy button , but it looks like firefox now removed this capability of copying to clipboard from the client site.

And here is the snippet that I used for chrome and its working great !!

else if (navigator.userAgent.toLowerCase().indexOf("chrome") != -1) {           
          var success   = true,
           range     = document.createRange(),
           selection;
           
var tmpElem = $('
');
           tmpElem.css({
             position: "absolute",
             left:     "-1000px",
             top:      "-1000px"
           });
          
           tmpElem.text(maintext);
           $("body").append(tmpElem);
           
           range.selectNodeContents(tmpElem.get(0));
           selection = window.getSelection ();
           selection.removeAllRanges ();
           selection.addRange (range);
           
           document.execCommand('copy');
          }

So with this I thought of looking if something new is available in the firefox to achieve this functionality.

Thanks,

more options

When you try the code you use for Chrome in Firefox, do you get an error on execCommand('copy')? According to the documentation, it should work if the document is in designMode: https://developer.mozilla.org/docs/Web/API/Document/execCommand