S
S
Sergey Predvoditelev2012-09-17 18:28:16
JavaScript
Sergey Predvoditelev, 2012-09-17 18:28:16

"Copy" function in Firefox

I am writing a custom script for greasemonkey. It is necessary to implement the function of copying text. Something the search did not give anything good. Tell me, is this possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrMig, 2012-09-17
@MrMig

You can't achieve this with javascript. Although, if the script is only for Firefox, then try

function copyToClipboard(text){  
        unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
        var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].
        getService(Components.interfaces.nsIClipboardHelper);  
        clipboardHelper.copyString(text);
    }
}

Otherwise, look here: https://github.com/jonrohan/ZeroClipboard
One significant disadvantage is that this solution requires a flash.
There are old articles:
http://brooknovak.wordpress.com/2009/07/28/accessing-the-system-clipboard-with-javascript/
and
http://almaer.com/blog/supporting-the-system-clipboard -in-your-web-applications-what-a-pain

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question