Skip to main content
Participant
February 1, 2020
Answered

Adobe CEP v9, I cant seem to copy the HTML text from panel to the OS Clipboard with javascript

  • February 1, 2020
  • 1 reply
  • 895 views

I am working on an extension for Adobe Bridge with CEPv9

 

Once my extension is loaded, I can select text in the panel manually with the mouse and right-click to copy. then proceed to paste outside of Bridge into other programs via normal OS copy/paste functions.

 

However, I cant seem to get the same .innerHTML text in the Panel to copy using a javascript function

 

Following the basic example on w3schools 

 

my javascript:

 

 var cText = document.getElementById("fileNameTable").innerHTML;
  alert("cText = " + cText);
  cText.select();
  cText.setSelectionRange(0, 99999);
  cText.copy(); //example says document.execCommand("copy");

 

 

The alert shows the text without issues, so i dont have a problem pulling the data.

 

Big picture, there is an html button that calls a function, said function would copy html text of specific element to the clipboard, user can then paste into another program.

 

I am a hobbyist to javascript so not sure where to look for answers.

 

and I wonder if this is Adobe preventing the command from working for security reasons?

 

Thank you.

    This topic has been closed for replies.
    Correct answer protomojo

    I was able to locate an answer.

     

    It seems that the .select() function only works on very specific HTML fields. Specifically related to user input.

     

    So the trick is to create a hidden user input field, put the data you have into the hidden input field .innerHTML and then use .select() on that input field. Doing so allows you copy the data to the OS clipboard.

     

    function click_copyList(){
    
       var copyText = document.getElementById("fileNameTable").innerText; // gets text from table
       document.getElementById("holdText").innerText = copyText;//send table text to input field
       document.getElementById("holdText").select();//select or highlight the input field text
       document.execCommand("copy");//copy selected text
    
    alert("copied the text!");
    } //end copyList

     

    1 reply

    protomojoAuthorCorrect answer
    Participant
    February 6, 2020

    I was able to locate an answer.

     

    It seems that the .select() function only works on very specific HTML fields. Specifically related to user input.

     

    So the trick is to create a hidden user input field, put the data you have into the hidden input field .innerHTML and then use .select() on that input field. Doing so allows you copy the data to the OS clipboard.

     

    function click_copyList(){
    
       var copyText = document.getElementById("fileNameTable").innerText; // gets text from table
       document.getElementById("holdText").innerText = copyText;//send table text to input field
       document.getElementById("holdText").select();//select or highlight the input field text
       document.execCommand("copy");//copy selected text
    
    alert("copied the text!");
    } //end copyList