I've created a class for copying text by creating a textarea and
running execCommand('Copy') on it. There is a 'Paste' command too but
somehow it won't work (I might be doing it wrong).

Feel free to use it if you'd like.

Code:

    Clipboard = {};
    Clipboard.utilities = {};

    Clipboard.utilities.createTextArea = function(value) {
        var txt = document.createElement('textarea');
        txt.style.position = "absolute";
        txt.style.left = "-100%";

        if (value != null)
            txt.value = value;

        document.body.appendChild(txt);
        return txt;
    };

    Clipboard.copy = function(data) {
        if (data == null) return;

        var txt = Clipboard.utilities.createTextArea(data);
        txt.select();
        document.execCommand('Copy');
        document.body.removeChild(txt);
    };

    // Can't get this to work. See the problem?
    Clipboard.paste = function() {
        var txt = Clipboard.utilities.createTextArea();
        txt.focus();
        document.execCommand('Paste');
        var value = txt.value;
        document.body.removeChild(txt);
        return value;
    };

Demo at: http://jsbin.com/uvivi

On Nov 29, 8:16 am, Phil Crosby <[email protected]> wrote:
> Woops, sorry about that. Filed 
> here:http://code.google.com/p/chromium/issues/detail?id=28941
>
>
>
> On Sat, Nov 28, 2009 at 10:10 PM, PhistucK <[email protected]> wrote:
> > You have linked to the wrong issue.
> > ☆PhistucK
>
> > On Sun, Nov 29, 2009 at 05:10, Phil Crosby <[email protected]> wrote:
>
> >> My extension also requires this capability, to copy the current page's
> >> URL to the clipboard via a keystroke.
>
> >> I've filed this as a feature request here:
> >>http://code.google.com/p/chromium/issues/detail?id=27591
>
> >> On Nov 24, 8:22 pm, Moses <[email protected]> wrote:
> >> > Auto copy selected text toclipboardwithout press Ctrl-C.
>
> >> > On Nov 25, 3:41 am, Antony Sargent <[email protected]> wrote:
>
> >> > > We don't currently have an API for this, but might in the future. What
> >> > > use
> >> > > case did you have in mind?
>
> >> > > On Tue, Nov 24, 2009 at 11:20 AM, Jean-Lou Dupont
> >> > > <[email protected]>wrote:
>
> >> > > > Is there a way to access theclipboard, if only to read its contents?
>
> >> > > > --
>
> >> > > > You received this message because you are subscribed to the Google
> >> > > > Groups
> >> > > > "Chromium-extensions" group.
> >> > > > To post to this group, send email to
> >> > > > [email protected].
> >> > > > To unsubscribe from this group, send email to
>
> >> > > > [email protected]<chromium-extensions%2Bunsu
> >> > > > [email protected]>
> >> > > > .
> >> > > > For more options, visit this group at
> >> > > >http://groups.google.com/group/chromium-extensions?hl=en.
>
> >> --
>
> >> You received this message because you are subscribed to the Google Groups
> >> "Chromium-extensions" group.
> >> To post to this group, send email to [email protected].
> >> To unsubscribe from this group, send email to
> >> [email protected].
> >> For more options, visit this group at
> >>http://groups.google.com/group/chromium-extensions?hl=en.

--

You received this message because you are subscribed to the Google Groups 
"Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/chromium-extensions?hl=en.


Reply via email to