Copy to clipboard

Hi, I am trying to create a button that copies a text to the clipboard from the dashboard but I can't do it in any way or with any node, could someone who has done something similar help me? Thank you

You could probably use a bash script to copy to clipboard if you are using linux/mac , and then execute that bash script via node-red exec node...

im using node-red in windows

Well i think this answer will help you , just make sure to format the command string properly with the value you want to copy, and then execute the command via exec node :smiley:

but this only works with one permanent text no?, i want to take variable text from dashboard and copy it to my clipboard by clicking a button of dashboard.

You can do this using the dashboard template node.

  1. Copy paste https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_copy_clipboard in the template node.
  2. Then you can further modify the html/javascript of the template node to your needs.
  3. I would send the dynamic text to copy to the clipboard as msg.payload to the template node.
  4. In template node code you can refer to the payload by {{msg.payload}}
2 Likes

This is even better solution than mine :grin:

If you implement msg.payload instead of the abc, it would work. But janvda method is 100% better than mine, and it will copy on any device, my script will only copy on server side.

This is down to your browser and OS, not Node-RED.

Allowing the browser to control access to the clipboard is fraught with security issues which is why it isn't necessarily easy.

Please share what browser you want to target.

Thank you, it works as I wanted.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.