mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
feat(client): implement clipboard fallback method
This commit is contained in:
parent
ac0f6662a6
commit
3ca2b24db3
@ -120,8 +120,18 @@ export function copyText(text: string) {
|
|||||||
if (navigator.clipboard) {
|
if (navigator.clipboard) {
|
||||||
navigator.clipboard.writeText(text);
|
navigator.clipboard.writeText(text);
|
||||||
succeeded = true;
|
succeeded = true;
|
||||||
|
} else {
|
||||||
|
// Fallback method: https://stackoverflow.com/a/72239825
|
||||||
|
const textArea = document.createElement("textarea");
|
||||||
|
textArea.value = text;
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.focus();
|
||||||
|
textArea.select();
|
||||||
|
succeeded = document.execCommand('copy');
|
||||||
|
document.body.removeChild(textArea);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.warn(e);
|
||||||
succeeded = false;
|
succeeded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user