detect what is copied from webpage with jquery

前端 未结 1 1709
悲&欢浪女
悲&欢浪女 2021-01-25 07:02

I have a question about jquery.

I know we can detect copy with jquery like this :

$(\"#textA\").bind(\'copy\', function() {
    $(\'span\').text(\'copy b         


        
相关标签:
1条回答
  • 2021-01-25 07:34

    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

    0 讨论(0)
提交回复
热议问题