views:

66

answers:

3

Hi,

I want to simulate a ctrl+c to copy the text into it. 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, doesn't run.

Anyone can help me with this? Thanks for read this.

+2  A: 

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.

Ross
Not sure if this still works with Flash versions > 10... that plugin is pretty old too.
fudgey
Im sure it doesnt run now , i have test it .
Angelus
hmm, well as fudgey said it is quite old. I recalled using it once upon a time. sorry its no use!
Ross
+1  A: 

Check out ZeroClipboard... I think it works, but I haven't tested it.

fudgey
A: 

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.

Tim Down