1.0.6 • Published 2 years ago
copy-resource v1.0.6
CopyResource
使用现代化的 clipboard API 将各种资源复制到剪辑板
目前支持文本、图片、HTML, 其他类型需等待 clipboard API 支持
const { copyResource } = import 'copy-resource';
// 复制文本
const text = '文本内容';
copyResource(text)
.then(() => console.log('复制成功'))
.catch((err) => console.log(`复制失败 err: ${err.message}`));
// 复制图片
const img = document.querySelector('#logo');
copyResource(img);
// 获取当前网页 html 内容
// 为了分辨是文本还是网址 需要构建 UrlResource 对象
copyResource(new UrlResource('./'));
浏览器支持
62 ✔ | 63 ✔ | 13.1 ✔ | 49 ✔ | 79 ✔ | 不支持 ✖ |
Installing
Using npm:
$ npm install copy-resource
Using bower:
$ bower install copy-resource
Using yarn:
$ yarn add copy-resource