function copyToClipboard(textToCopy) {
// navigator clipboard 需要https等安全上下文
if (navigator.clipboard && window.isSecureContext) {
// navigator clipboard 向剪贴板写文本
return navigator.clipboard.writeText(textToCopy).then(function () {
layer.msg("复制成功Https!", { icon: 1 })
});
} else {
// 创建text area
let textArea = document.createElement("textarea");
textArea.value = textToCopy;
// 使text area不在viewport,同时设置不可见
textArea.style.position = "absolute";
textArea.style.opacity = 0;
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
return new Promise((res, rej) => {
// 执行复制命令并移除文本框
layer.msg("复制成功Http!", { icon: 1 });
document.execCommand('copy') ? res() : rej();
textArea.remove();
});
}
}

最新文章

  1. shell script 执行常用的两种方式
  2. 使用keychain保存用户名和密码等敏感信息 KeychainItemWrapper和SFHFKeychainUtils
  3. 关于Android中查看app安装时间等信息的问题
  4. FileZilla FTP Server 高级防火墙例外
  5. IE6-BUG-CSS兼容详解
  6. iOS_SN_LLDB常用命令
  7. solr 分词词库管理思路
  8. 用VS Code体验调试.NET Core 2.0 Preview (传统三层架构)
  9. yaf代码生成工具的使用
  10. CentOS6.8 安装node.js npm
  11. 2.静态AOP实现-装饰器模式
  12. Zend Optimizer,Zend Guard Loader 和 Zend Opcache 三者之间的区别
  13. TensorFlow占位符操作:tf.placeholder_with_default
  14. oracle 行号和分页
  15. POJ 3579 3685(二分-查找第k大的值)
  16. 启动exe
  17. Dubbo集群配置和官方文档
  18. win7开始菜单路径
  19. 微信小程序奇奇怪怪的语法
  20. 如何释放vector变量

热门文章

  1. YII页面缓存
  2. Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
  3. show create table底层流程跟踪
  4. StarRocks 运维工具 StarGo
  5. C#基础_VS常用快捷键
  6. 究竟什么是Shadow DOM?
  7. 在Laravel框架blog中,终端的一些命令
  8. Spring MVC组件之HandlerAdapter
  9. Linux虚拟机启动报错挂载点丢失
  10. 从零打造“乞丐版” React(一)——从命令式编程到声明式编程