使用Javascript复制到剪贴板 [英] Copy to clipboard using Javascript

查看:86
本文介绍了使用Javascript复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个隐藏字段如下。



< input id =hdnKopierModtagereclass =hdnKopierModtageretype =hiddenrunat =server/>



此字段的值在代码隐藏中设置。



点击按钮,我必须将隐藏控件中的文本复制到剪贴板。



我在谷歌搜索了很多,但大多数人建议使用Flash或ZeroClipboard。但是我不能用这个。



我需要一个纯javascript来将文本复制到剪贴板,它应该在以下浏览器中支持(IE,Mozilla和Chrome )。请告诉我如何继续。



提前致谢。

解决方案

查看任何代码示例在任何CodeProject文章或答案中。您会在每个代码的右上角看到复制代码锚点(< pre> )元素。单击此锚点并查看其功能。我建议你做同样的事情。它可以帮助读者轻松地以非侵入方式复制剪贴板中的文本,与您尝试的方式形成对比。



-SA

Hi All,

I have a hidden field as below.

<input id="hdnKopierModtagere" class="hdnKopierModtagere" type="hidden" runat="server" />

The value of this field is set in the code-behind.

On clicking a button, i have to copy the text from the hidden control to the clipboard.

I have searched in google a lot, but most of them recommend to use Flash or ZeroClipboard. But I can't use this.

I need a pure javascript to copy the text to the clipboard and it should be supported in following browsers (IE, Mozilla and Chrome). Kindly advice me know how to proceed.

Thanks in advance.

解决方案

Look at any code sample in any CodeProject article or answer. You will see "Copy code" anchors over the right top corner of each code ("<pre>") element. Click at this anchor and see what it does. I suggest you do exactly the same thing. It helps the reader to easily copy the text in the clipboard in a non-intrusive manner, in contrast to what you are trying to do.

—SA


这篇关于使用Javascript复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆