G Web Development Software

cancel
Showing results for 
Search instead for 
Did you mean: 

Copy one string to windows clipboard use Javascript in LabVIEW Web module

Hi:

I would like to copy one string to windows clipboard use Javascript in LabVIEW NXG web module.

The UI operation process is to put the "MES_EXP" string into the clipboard after user push down "Copy MES_EXP" button.

I had found the Java code for this app on the web, and I have tried many times to modify it according to the documentation on the NI official website.

However, it still doesn't work, I don't know where the error is, and since I don't have the ability to edit Java programs.

I'm hoping someone can provide this example to help me step to step how to use Javascript in LabVIEW NXG Web (or G Web) development.

I will keep trying and never give up. 😊

Anyway, thank you for reading this.

 

Best regards

Joe

 

Attach some information as follows:

 LabVIEW Web UI:

Joe_Tang_1-1672202436203.png

 

Javascript: (Reference: " https://stackabuse.com/how-to-copy-to-clipboard-in-javascript-with-the-clipboard-api/ " )

Joe_Tang_2-1672202461217.png

 

Create JSLI in LabVIEW program:

Joe_Tang_4-1672202514750.png

0 Kudos
Message 1 of 3
(1,771 Views)

Hi Joe,

 

In this case you can have the JSLI document call the navigator.clipboard.writeText function directly:

 

MilanR_0-1672702805533.png

 

As the writeText function can be passed a string according the the MDN Clipboard.writeText documentation.

 

Note that the documentation states that using the writeText api requires "transient user activation". This means that you can only invoke the Write Text VI created by the JSLI in response to a user interaction. A good example is to call it in response to a button click event like the following:

 

MilanR_1-1672703225986.png MilanR_2-1672703289010.png

 

Finally note that the G Web Development Software editor is based on Chrome 64 which does not support this feature. So running the Write Text VI inside the editor will result in an error. To test the behavior you need to use Run in Browser or build and deploy the WebVI to test in a modern browser.

 


Milan
Message 2 of 3
(1,635 Views)

Hi Milan:

Thank you very much, it works now.

I had been succeeded to test the behavior use Run in Browser (Edge).

And first time, I need to accept to use the clipboard in Browser.

Thank you very much.

.^_^.

Joe

Message 3 of 3
(1,566 Views)