We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9ed2e25 commit c01895aCopy full SHA for c01895a
src/utils/copy.ts
@@ -6,6 +6,19 @@ document.addEventListener('copy', (e) => {
6
e.preventDefault()
7
})
8
9
-export function copyToClip(text: string) {
10
- return navigator.clipboard.writeText(text)
+export async function copyToClip(text: string) {
+ // https://stackoverflow.com/questions/51805395/navigator-clipboard-is-undefined
11
+ if (navigator.clipboard && window.isSecureContext) {
12
+ await navigator.clipboard.writeText(text)
13
+ }
14
+ else {
15
+ const input: HTMLTextAreaElement = document.createElement('textarea')
16
+ input.setAttribute('readonly', 'readonly')
17
+ input.value = text
18
+ document.body.appendChild(input)
19
+ input.select()
20
+ if (document.execCommand('copy'))
21
+ document.execCommand('copy')
22
+ document.body.removeChild(input)
23
24
}
0 commit comments