admin管理员组文章数量:1320619
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 acplish all this.
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 acplish all this.
- 1 I assume that you want to do this in a browser? – Davin Tryon Commented Jun 30, 2017 at 15:26
- @DavinTryon Ah, yes! I forgot to mention that I am building a web application, however, produced in a batch file. I am testing and running in web, but the production will ultimately be in a batch file. – gatsbyz Commented Jun 30, 2017 at 15:28
- Possible duplicate of How do I copy to the clipboard in JavaScript? – evolutionxbox Commented Jun 30, 2017 at 15:29
- 1 So you want to copy to the clipboard from node? – Davin Tryon Commented Jun 30, 2017 at 15:29
- 1 @PraveenKumar Haha. No problem :) I actually liked your edit better. – gatsbyz Commented Jun 30, 2017 at 19:09
1 Answer
Reset to default 7As 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.
本文标签: JavascriptHow can I copy a text to clipboard without displaying a textareaStack Overflow
版权声明:本文标题:Javascript - How can I copy a text to clipboard without displaying a textarea? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742077404a2419488.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论