Copying to Clipboard

4,041 views
Skip to first unread message

master

unread,
May 3, 2011, 11:08:36 AM5/3/11
to Chromium-extensions
The problem is how to copy over some text into user clipboard.

- The experimental api allows this but not allowed in extensions to be
uploaded.
- The javascript call to copy to clipboard not allowed .
- The routing through flash also not working.

Any other alternate solutions?

Boris Smus

unread,
May 3, 2011, 11:33:00 AM5/3/11
to master, Chromium-extensions
There is a long thread about this here: http://stackoverflow.com/questions/400212/how-to-copy-to-clipboard-in-javascript. At the moment, the best way to do this is still by going through a small flash object.

- Boris


--
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.


Scott Fujan

unread,
May 3, 2011, 1:39:07 PM5/3/11
to master, Chromium-extensions

Javascript call is allowed -- but only in the background page.
Flash should work.

Anil Shanbhag

unread,
May 3, 2011, 3:51:16 PM5/3/11
to Scott Fujan, sm...@chromium.org, Chromium-extensions
*

Zero Clipboard Does Not Work From Local Disk

This is a security restriction by Adobe Flash Player. Unfortunately, since we are utilizing the JavaScript-to-Flash interface ("ExternalInterface") this only works while truly online (if the page URL starts with "http://" or "https://"). It won't work running from a local file on disk.

*

I havent tried with background page yet but will try.


-- 
Regards
Anil Shanbhag 

**Thats the new google url shortner - to shorten my site link 

watts

unread,
May 4, 2011, 11:30:09 AM5/4/11
to Chromium-extensions
I just solved this yesterday (my variable name is lacking but this
works rather well - for Windows anyways).

1) Add this to the background page:
<script>
chrome.extension.onRequest.addListener(function(request, sender,
sendResponse) {
if(request.entry != "") {
clipCopy(request.entry);
sendResponse({});
}
});

function clipCopy(text) {
clipboardholder= document.getElementById("clipboardholder");
clipboardholder.style.display = "block";
clipboardholder.value = text;
clipboardholder.select();
document.execCommand("Copy");
clipboardholder.style.display = "none";
}
</script>
<textarea id="clipboardholder" style="display:none;"></textarea>


2) Add this to the content script:
function copyme(text) {
chrome.extension.sendRequest({entry: text}, function(response) {
});

watts

unread,
May 4, 2011, 11:33:15 AM5/4/11
to Chromium-extensions
Reply all
Reply to author
Forward
0 new messages