6.0 there is no Clipboard API in Google Chrome browser.
Google is experimenting on that in Development builds of Chrome browser and the Experimental Clipboard API is available to test only in these builds. It makes it impossible to use in production.
But the answer comes from the remembering that Chrome Extension is a plain HTML and JavaScript where the regular DOM and BOM structures are available.
Copying text to Clipboard in HTML/JavaScript requires three simple steps:
- Put text to the input element
- Focus on that element and select all text you need to copy
- Execute DOM's "Copy" command that gets the current selection and puts to the clipboard automatically
// Copy text to the Clipboard function
// uses 'url' input element to select text
// parameters: text - text to be copied to the clipboard
function copyToClipboard( text )
{
var input = document.getElementById( 'url' );
input.value = text;
input.focus();
input.select();
document.execCommand( 'Copy' );
}
sposibo, but unfortunately this does not seem to work : / ( i put your code in my popup.html and added a textarea which was called 'url')
ReplyDeleteAWESOME !
ReplyDeleteIt's works . thank you
Just amazing, works for me :)
ReplyDeleteIt doesnt work at Chrome!
ReplyDeleteLeonid,
ReplyDeletePlease clarify if you have ever seen this work on Chrome.
It does not work on Chrome for me.
Tested on 27-Jul-2012. Using Windows 7 64 bits and Chrome 20.0.1132.57
make it at the mouseup event becaus the mouse up event remove the selection
ReplyDeleteIt doesn't work in content script. It works in popup extension, but not when I've tried to modify some pages...
ReplyDelete