diff --git a/src/code/index.js b/src/code/index.js index ea4f60b..923371b 100644 --- a/src/code/index.js +++ b/src/code/index.js @@ -212,7 +212,18 @@ class Code extends Component { } copyCode() { - navigator.clipboard.writeText(this.code) + if (navigator.clipboard) { + navigator.clipboard.writeText(this.code) + } else { + let ta = document.createElement('textarea') + ta.style.position = 'fixed' + ta.style.left = '-2000px' + ta.value = this.code + this.root.appendChild(ta) + ta.select() + document.execCommand('copy') + ta.remove() + } layer.toast('复制到粘贴板成功', 'success') }