[英]Javascript - How can I copy a text to clipboard without displaying a textarea?
I'm trying to copy to the user's clipboard a path to the log files in Javascript.我正在尝试将 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.
谢谢。
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正如您已经从其他帖子中阅读的那样,由于浏览器安全性,您需要将 textarea 或 textbox 复制到剪贴板,如果您不想显示 textbox 或 textarea,只需将其隐藏,您可以使用
.hide {
position:absolute;
left:-9999px
}
left: value should be greater either positive or negative, ie it does not fall into any current screen visible width. left:值应该大于正值或负值,即它不属于任何当前屏幕可见宽度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.