Reputation: 209
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?
Upvotes: 1
Views: 931
Reputation: 271
\ is the JavaScript escape character.
To use a backslash use \\
.
Further reading: https://www.w3schools.com/js/js_strings.asp
Upvotes: 0
Reputation: 843
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.
Upvotes: 3