the proper use of execcommand(“paste”) in a chrome extension

后端 未结 3 1746
南方客
南方客 2020-11-29 23:21

I\'m trying to paste clipboard data into a textarea using execcommand(\"paste\") with a chome extension, but i cannot seem to get it to work. permissions are s

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 00:14

      function PasteString() {
        var editor = document.getElementById("TemplateSubPage");
        editor.focus();
      //  editor.select();
        document.execCommand('Paste');
    }
    
    function CopyString() {
        var input = document.getElementById("TemplateSubPage");
        input.focus();
       // input..select();
        document.execCommand('Copy');
        if (document.selection) {
            document.selection.empty();
        } else if (window.getSelection) {
            window.getSelection().removeAllRanges();
        }
    }
    

    Hope this will work for you

提交回复
热议问题