detect what is copied from webpage with jquery

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?

Answers:

Answer

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

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.