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
});
}
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.
To check whether user pressed ENTER key on webpage or on any input element, you can bind keypress or keydown event to that element or document object itself. Then in bind() function check the keycode of pressed key whether it's value is 13 is not.
To detect the combination of keys with “Ctrl”, we use the ctrl property of the keydown event. It returns a “boolean” value to tell if “ctrl” is pressed or not when the key event got triggered.
The keypress event is fired when a key that produces a character value is pressed down. Examples of keys that produce a character value are alphabetic, numeric, and punctuation keys. Examples of keys that don't produce a character value are modifier keys such as Alt , Shift , Ctrl , or Meta .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With