I want to simulate Ctrl+C to copy the text from a page. I first tried this:
$('#codetext').click( function() {
$("#codetext").trigger({
type: 'keydown',
which: 99
});
}
开发者_StackOverflow中文版HTML:
<input type='text' id='codetext'>
I have also tried using $(this)
instead of the selector, but the input element also has focus on it, so it doesn't run.
Check out ZeroClipboard... I think it works, but I haven't tested it.
not sure how to trigger ctrl+c, but there's a JQuery clipboard plugin that may be of some use:
http://plugins.jquery.com/project/copy
$("#elmID").copy() // copy all text inside #elmID.
You cannot trigger a cut, copy or paste programmatically in JavaScript (at least, not in most browsers). These actions can only come from the user. If you need to do this you'll need some kind of hack like the Flash-based things in other answers but I wouldn't even rely on them working forever.
Ctrl+C event mainly used for copy content.
I tried to trigger this event on summernote.
While trying, I could know that document.execCommand('copy')
can touch this problem.
Like this you may trigger cut, paste event by using document.execCommand('cut')
and document.execCommand('paste')
.
精彩评论