0

I'm trying to create a button that when clicked will copy a text to clipboard.

<button onclick="copyToClipboard('A\B\C\D')">Click here</button>

but when using this approach, the text copied to the clipboard is:

ABCD

instead of

A\B\C\D

Can someone help here please?

Hugo Silva
  • 199
  • 9

2 Answers2

1

You can try:

<button onclick="copyToClipboard('A\\B\\C\\D')">Click here</button>

or

<button onclick="copyToClipboard('A/B/C/D')">Click here</button>

and see if any of the two will work for your task.

Borislav Aymaliev
  • 803
  • 2
  • 9
  • 20
0

\ is the JavaScript escape character. To use a backslash use \\.

Further reading: https://www.w3schools.com/js/js_strings.asp

Zeronull
  • 261
  • 3
  • 5