当前位置:网站首页>JS implements the method of copying contents to the clipboard
JS implements the method of copying contents to the clipboard
2022-06-09 15:08:00 【Don't stare at my name】
Replication method
/**
* Copy function
* text Pass in the text to copy
* callback Callback after copying
*/
function copy(text, callback) {
// Implement replication method 1 :
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
callback && callback(true);
return;
}
// Implementation of replication method 2 :
var copyInput = document.getElementById('copyInput');
if (!copyInput) {
var copyInput = document.createElement('input');
copyInput.setAttribute('id', 'copyInput');
copyInput.style.position = 'fixed';
copyInput.style.left = '-100%';
copyInput.style.top = '0';
copyInput.style.zIndex = -100;
copyInput.style.opacity = 0;
document.body.appendChild(copyInput);
}
copyInput.value = text;
copyInput.focus();
copyInput.select();
// document.execCommand May be abandoned
if (document.execCommand('copy')) {
document.execCommand('copy');
}
copyInput.blur();
callback && callback(true);
}Calling method
copy(' Pass in the text you want to copy ');Related articles
边栏推荐
- 【实战】Redis Cluster(下)-系统版本支持问题
- 程序员高考卷曝光,你能得多少分?
- Huawei announced its top ten inventions: efficient additive network and multi-objective game intelligent driving
- Why do SQL statements use indexes but still slow queries?
- Critical area, event, mutex, semaphore -- four methods to control multithread synchronization and mutex
- 小程序转盘抽奖组件
- 新冠病毒的最终解药
- 薪酬不變,每周只上四天班,英國試行全球最大規模“四天工作制”
- @Enablefeignclients annotation source code analysis
- 期货开户去哪里开?网上开户安不安全?
猜你喜欢

@Enablefeignclients annotation source code analysis

各厂商的数据湖解决方案

How greatsql is a popular open source database in China

Qt msvc编译器中文问题解决,中文乱码以及无法正常编译

数据库中错误1062,报错

鸿蒙移植i.mx6ull(五) 移植概述

最成功也最差劲的CEO去世,索尼还是走在他的老路上

Details on how Tencent can reduce the live broadcast delay by more than 90%
![[paper] cascade r-cnn: delving into high quality object detection](/img/7d/f5ebd89cd8963fe45d4894077ca25b.png)
[paper] cascade r-cnn: delving into high quality object detection

Fcpx plug-in: motion blur FX by Ma
随机推荐
Taoist friends! What is the expiration policy of redis?
Gaussdb (DWS) functions and supporting tools [Gauss is not a mathematician this time]
How greatsql is a popular open source database in China
鸿蒙移植i.mx6ull (七) Liteos-a的编译系统
QT MSVC compiler Chinese problem solving, Chinese garbled and unable to compile normally
ECCV 2020 | star: pedestrian trajectory prediction model based on transformer (II)
鸿蒙移植i.mx6ull(六) Kconfig_GCC_Mkefile
鸿蒙移植i.mx6ull(八) 添加一个单板
2022年6月中国数据库排行榜:TiDB卷土重来摘桂冠,达梦蛰伏五月夺探花
How insecure is NFT from copyright to assets?
鸿蒙移植i.mx6ull(八) 内存映射(基于IMX6ULL)
【实战】Redis Cluster(上)-环境搭建
Details on how Tencent can reduce the live broadcast delay by more than 90%
CICC digital intelligence China II: five questions and five answers to database business market
鸿蒙移植i.mx6ull(九) 串口移植(基于IMX6ULL)
Error 1062 in database, error reporting
数据库中错误1062,报错
期货网上开户安全吗?期货妙手机开户吗?
【云小课】应用平台第43课 云小课带您快速入门多云高可用服务
国货彩妆,败走618