fix: change async clipboard api with execCommand
This commit is contained in:
parent
e3f16f1dd6
commit
e0003064f1
|
|
@ -20,9 +20,19 @@ export default class Clipboard {
|
||||||
|
|
||||||
_handleCopy(e) {
|
_handleCopy(e) {
|
||||||
this._remoteClipboard = e.clipboardData.getData('text/plain');
|
this._remoteClipboard = e.clipboardData.getData('text/plain');
|
||||||
if (navigator.clipboard.writeText) {
|
this._copy(this._remoteClipboard)
|
||||||
navigator.clipboard.writeText(this._remoteClipboard).catch(() => {/* Do nothing */});
|
}
|
||||||
}
|
/**
|
||||||
|
* Has a better browser support compared with navigator.clipboard.writeText.
|
||||||
|
* Also, no permission required.
|
||||||
|
*/
|
||||||
|
_copy(text) {
|
||||||
|
const textarea = document.createElement('textarea');
|
||||||
|
textarea.innerHTML = text;
|
||||||
|
document.body.appendChild(textarea);
|
||||||
|
textarea.select();
|
||||||
|
const result = document.execCommand('copy');
|
||||||
|
document.body.removeChild(textarea);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {ClipboardEvent} e
|
* @param {ClipboardEvent} e
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue