Reputation: 215
I have a question about jquery.
I know we can detect copy with jquery like this :
$("#textA").bind('copy', function() {
$('span').text('copy behaviour detected!')
});
$("#textA").bind('paste', function() {
$('span').text('paste behaviour detected!')
});
$("#textA").bind('cut', function() {
$('span').text('cut behaviour detected!')
});
But , i want to know what is exactly copied ?
for example, user copy the value of one box, i need to get and have that value .
How to do this with jquery?
Upvotes: 1
Views: 588
Reputation: 2919
You can use this
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
$(document).keypress("c",function(e) {
if(e.ctrlKey)
alert(getSelectionText());
});
this should be work
Upvotes: 3