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

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

问题描述

我正在为 Google Chrome 制作扩展程序,但遇到了障碍.

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

我需要在弹出窗口中单击时将只读文本区域的内容复制到剪贴板.有没有人知道用纯 Javascript 和没有 Flash 来解决这个问题的最佳方法?我还在扩展中加载了 jQuery,如果有帮助的话.我当前的(非工作)代码是...

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."); }

推荐答案

您可以使用 实验剪贴板 API,但它仅在浏览器的开发分支中可用,默认情况下不启用 (更多信息)..

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天全站免登陆