在 Firefox 和 google chrome 上复制到剪贴板
因为我环顾四周,找不到任何将 Firefox 或 Chrome 上的文本复制到剪贴板的好解决方案。但是,我尝试了 Firefox 在其开发者站点中提供的一些代码,但仍然无法正常工作,并且出现一个错误,权限被拒绝。这是我在最后一刻尝试的代码。
var copytext = "Text to copy";
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
str.data = copytext;
有没有人有一个好的解决方案来处理这个问题?我将感谢您的分享。谢谢。
since I have looked around and could not find any nice solution for copying text on firefox or chrome to clipboard. However, I have tried some codes provide by firefox in its developer site, but still not work and there was one errror with permission denied. Here is the code I tried the last minute.
var copytext = "Text to copy";
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
str.data = copytext;
Does anyone have a good solution to deal with this? I would appreciate for your sharing. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想这不仅仅是为了你看?
如果没有,您可以在 Firefox 浏览器中调整 about:config 中的设置。在过滤器中查找“signed”,并将单个结果设置为“禁用”。
然而,如果您想要整个事情的代码,那就有点麻烦了,因为 Firefox 对此有很好的安全保护。一种棘手的方法是使用 Flash 对象将字符串传递给,然后使用 Flash 复制到剪贴板:)
I take it it's for more than just you viewing?
If not, you can adjust the setting in about:config in your Firefox browser. Look for 'signed' in the filter, and set the single result to DISABLED.
However, if you want code for the whole thing, it's tricker as Firefox is quite well secured against that. One tricky way is to use a Flash object to pass the string to, and then use Flash to copy to the clipboard :)
我找到了下一个解决方案:
在按键处理程序上创建“pre”标签。设置要复制到此标签的内容。在此标签上进行选择并在处理程序中返回 true。这会调用 chrome 的标准处理程序并复制所选文本。
如果您需要,您可以为恢复先前选择的功能设置超时。我在 Mootools 上的实现:
用法:
在粘贴时创建文本区域并且工作相同。
抱歉英语不好——不是我的母语。
I am found next solution:
On key down handler create "pre" tag. Set content to copy to this tag. Make Selection on this tag and return true in handler. This call standard handler of chrome and copied selected text.
And if u need u may be set timeout for function for restoring previous selection. My implementantions on Mootools:
usage:
On paste its create textarea and work same.
Sorry for bad English - not my native language.