在Chrome扩展程序中复制到剪贴板 [英] Copy to Clipboard in Chrome Extension

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

问题描述

我正在对Google Chrome进行扩展,并遇到困难。

我需要在弹出窗口中点击只读textarea的内容到剪贴板。有没有人知道最好的方式去纯粹的Javascript和没有Flash的这个?如果有帮助的话,我也在扩展中加载了jQuery。我的当前(非工作)代码是...

 函数copyHTMLCB(){
$('#lb_html ')。选择();
$('#lb_html')。focus();
textRange = document.lb_html_frm.lb_html.createTextRange();
textRange.execCommand(RemoveFormat);
textRange.execCommand(Copy);
alert(HTML已被复制到剪贴板中。); }


解决方案

您可以使用实验性剪贴板API ,但它仅在浏览器的开发分支中可用,且未启用默认(更多信息)。


I'm making an extension for Google Chrome and I have hit a snag.

I need to copy a readonly textarea's content to the clipboard on click in the popup. Does anyone know the best way to go about this with pure Javascript and no Flash? I also have jQuery loaded in the extension, if that helps any. My current (non-working) code is...

function copyHTMLCB() {
$('#lb_html').select();
$('#lb_html').focus();
textRange = document.lb_html_frm.lb_html.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
alert("HTML has been copied to your clipboard."); }

解决方案

You can copy to clipboard using Experimental Clipboard API, but it is available only in the dev branch of a browser and not enabled by default (more info)..

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

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