https://github.com/x-extends/xe-clipboard
纯 js 实现复制文本到剪贴板,支持IE、Chrome、Firefox、Opera、Safari、IOS、Android
https://github.com/x-extends/xe-clipboard
clipboard
Last synced: over 1 year ago
JSON representation
纯 js 实现复制文本到剪贴板,支持IE、Chrome、Firefox、Opera、Safari、IOS、Android
- Host: GitHub
- URL: https://github.com/x-extends/xe-clipboard
- Owner: x-extends
- License: mit
- Created: 2018-12-29T10:05:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-15T12:56:24.000Z (about 2 years ago)
- Last Synced: 2025-02-15T16:50:11.407Z (over 1 year ago)
- Topics: clipboard
- Language: HTML
- Homepage:
- Size: 55.7 KB
- Stars: 50
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xe-clipboard
[](https://gitee.com/x-extends/xe-clipboard/stargazers)
[](https://www.npmjs.com/package/xe-clipboard)
[](http://npm-stat.com/charts.html?package=xe-clipboard)
[](LICENSE)
基于 [execCommand](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) API 实现复制内容到剪贴板,支持主流的 H5 浏览器 IE, Chrome, Firefox, Opera, Safari, IOS, Android
压缩大小 < 0.5KB
## Browser Support
 |  |  |  |  | 
--- | --- | --- | --- | --- | --- |
10+ ✔ | Latest ✔ | 42+ ✔ | 41+ ✔ | 29+ ✔ | 10+ ✔ |
## Installing
```shell
npm install xe-clipboard
```
```xml
```
## Example
```html
Copy
```
```javascript
document.getElementById('btn1').addEventListener('click', function (evnt) {
// 由于浏览器的安全机制,操作剪贴板必须在事件之内才能有效
if (XEClipboard.copy('Copy this content to the clipboard.')) {
alert('Copy success.')
} else {
alert('The browser is not supported.')
}
})
```
## Contributors
Thank you to everyone who contributed to this project.
[](https://github.com/x-extends/xe-clipboard/graphs/contributors)
## License
[MIT](LICENSE) © 2017-present, Xu Liangzhan