2

I'm trying to copy to the user's clipboard a path to the log files in Javascript. However, I do not wish to use an input field or textarea. Other solutions indicate that I should use an input field, select the text from the field, then copy it. Is there any workaround to have a code-defined string directly copied to my clipboard? Thanks.

  • I use plain JS and Node.js
  • I am trying to copy a text defined in my code (local path to log files) to the user's clipboard without using any user input fields (textarea, input tags). The other questions seem to either use user fields or 3rd party APIs. I do not want that! I am looking for some JS code that will accomplish all this.
Andhi Irawan
  • 456
  • 8
  • 15
gatsbyz
  • 1,057
  • 1
  • 10
  • 26

1 Answers1

7

As you have already read from other post, you need the textarea or textbox to copy to clipboard, because of browser security, If you don't want to show the textbox or textarea, just hide it, you can use

.hide {
  position:absolute;
  left:-9999px
}

left: value should be greater either positive or negative, i.e it does not fall into any current screen visible width.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252