复制到剪贴板在 FireFox 上不起作用
我已经实现了复制到剪贴板功能。它在 IE 上的所有版本上都能正常工作,但在 FireFox 上却无法工作。请帮我解决这个问题。 详细信息是
<script src="../../Scripts/JQPlugins/jquery.clipboard.js" type="text/javascript"></script>
<script src="../../Scripts/JQPlugins/jquery.clipboard.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$.clipboardReady(function() {
$("input#buttonid").bind('click', function() {
var text = $("#url").attr("href") + "\n" + $("#pwd").html();
$.clipboard(text);
alert("hi");
return false;
});
}, { swfpath: "../../Scripts/JQPlugins/jquery.clipboard.swf", debug: true });
</script>
我的代码文件结构是
Project > Scripts > JQPlugins >
1. jquery.clipboard.js
2. jquery.clipboard.pack.js
3. jquery.clipboard.swf
I had implemented copy to clipboard functionality. It is working fine with all version on IE but not working in FireFox. Please help me solve out this problem.
Detail are
<script src="../../Scripts/JQPlugins/jquery.clipboard.js" type="text/javascript"></script>
<script src="../../Scripts/JQPlugins/jquery.clipboard.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$.clipboardReady(function() {
$("input#buttonid").bind('click', function() {
var text = $("#url").attr("href") + "\n" + $("#pwd").html();
$.clipboard(text);
alert("hi");
return false;
});
}, { swfpath: "../../Scripts/JQPlugins/jquery.clipboard.swf", debug: true });
</script>
And my code file structure is
Project > Scripts > JQPlugins >
1. jquery.clipboard.js
2. jquery.clipboard.pack.js
3. jquery.clipboard.swf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将文本复制到剪贴板的方法是 jQuery 剪贴板插件;它使用 IE 的本机功能将文本复制到剪贴板,但在非 IE 平台上使用 Flash 插件。我敢打赌,您的计算机上有 Flash 10,或者至少在您测试 Firefox 的计算机上 — Flash 10 不再允许在没有明确用户请求的情况下进行剪贴板操作,这可能就是您看到它无法运行的原因火狐。 (甚至在插件的发行说明中提到了这一点。)
话虽这么说,人们已经已经找到了安全限制的解决方法;解决方法包括将不可见的 Flash 影片放置在您选择的 DOM 元素之上,这意味着当用户单击或以其他方式调用该元素来提交数据时,Flash 影片会注册用户采取了显式操作,并允许剪贴板操作。 Zero Clipboard 就是一个提供解决方法的库,但如果您寻找的话,还有其他库他们。
The method you're using to copy text to the clipboard is the jQuery clipboard plugin; it uses IE's native abilities to copy text to the clipboard, but uses a Flash plugin on non-IE platforms. My bet is that you have Flash 10 on your machine, or at least on the machine you're testing Firefox on -- Flash 10 no longer allows clipboard manipulation without explicit user request, which is likely why you're seeing it not work on Firefox. (This is even mentioned in the release notes for the plugin.)
That being said, people have already figured out a workaround for the security restrictions; the workaround involves placing an invisible Flash movie atop the DOM element of your choice, which means that when the user clicks or otherwise invokes the element to submit data, the Flash movie registers that the user took explicit action, and allows the clipboard manipulation. Zero Clipboard is one such library providing the workaround, but there are others out there if you look for 'em.
将 id 传递给函数: selectElementContents(document.getElementById("printtext"));
Pass the id to the functions : selectElementContents(document.getElementById("printtext"));