cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Implementing Client-Side JavaScript to Copy Text

Tomellache2B
14-Alexandrite

Implementing Client-Side JavaScript to Copy Text

Hi all,

 

I would like to copy my string from thingworx to my clipboard. I have found 2 ways of doing so in javascript.

1.  .execCommand("copy");

2. navigator.clipboard.writeText

 

the issue is that thingworx does not support these 2 methods because it is a client-side operation.

How can I incorporate my custom JavaScript code in my mashup?  What are the steps?

 

My ultimate goal is to copy text from a mashup to a clipboard.

Best Regards

2 REPLIES 2

@Tomellache2B  you can create a simple widget extension for the same purpose.

If you're entitled to ThingWorx Analytics, you can download the TWX Analytics Extension. It contains multiple sub-extensions you can install individually. One extension is called "CopyToClipboard-button" and you can use this either as it is or take it as a template.

The widget copies the value of it's bound "analyticsCopyToClipboardButton" Property to the clipboard. You would bind the copyToClipboard service to an event, e.g. a button click.

If you want to copy arbitrary selections, not just widget or service return values, you would have to change one function in the runtime.js to this (by removing some lines):

var copyPropertyToClipboardFunction = function(){
document.execCommand('copy');
}


 

Top Tags