[crx] How to copy text from popup

358 views
Skip to first unread message

arthur

unread,
Apr 23, 2010, 2:44:26 PM4/23/10
to Chromium-extensions
Hi All,

I am using a textarea in the popup.html to display output text. Since
there is no right-click menu item of 'copy' to let user to copy
selection out (even ctrl-c works), I am thinking to add a button to do
so. However, looks document.execCommand("copy"); doesn't work from
popup. Any workaround? Thanks. Arthur

My test popup.html:

<!DOCTYPE HTML>
<html>
<head>
<script>
function test1() {
var t = document.getElementById('showtextout');
t.selectionStart = 0;
t.selectionEnd = t.value.length;
}

function test2() {
// this not work in popup!!
document.execCommand("copy");
}

</script>
</head>
<body>
<div id='divout'>
<textarea id="showtextout" rows="25"
cols="50">qwertyuiop1234567890</textarea>
<p align="center">
<input type="button" value="Select All" onClick='test1();' />
<input type="button" value="Copy" onClick='test2();' />
</p>
</div>

</body>
</html>

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

Pedro Junior

unread,
Apr 23, 2010, 3:04:38 PM4/23/10
to arthur, Chromium-extensions
I can use an experimental api for this:

arthur

unread,
Apr 23, 2010, 5:09:34 PM4/23/10
to v.ju.n...@gmail.com, Chromium-extensions
Thanks. To support stable/beta users, I added a line to tell user to
press 'ctrl-c' to copy. Lazy way ;) Arthur
Pedro Junior wrote:
> I can use an experimental api for this:
> http://code.google.com/chrome/extensions/dev/experimental.clipboard.html
>
> 2010/4/23 arthur <mail2...@gmail.com <mailto:mail2...@gmail.com>>
> <mailto:chromium-...@chromium.org>.
> To unsubscribe from this group, send email to
> chromium-extens...@chromium.org
> <mailto:chromium-extensions%2Bunsu...@chromium.org>.
Reply all
Reply to author
Forward
0 new messages