Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async copyText(content) {
- try {
- await navigator.clipboard.writeText(content);
- } catch (e) {
- // polyfill if the browser doesn't support the clipboard api
- const textarea = document.createElement('textarea');
- textarea.style.opacity = 0;
- textarea.style.width = 0;
- textarea.style.height = 0;
- textarea.style.position = 'absolute';
- textarea.style.bottom = '-100%';
- textarea.style.left = '-100%';
- textarea.style.margin = 0;
- document.body.appendChild(textarea);
- textarea.value = content;
- textarea.select();
- document.execCommand('copy');
- textarea.remove();
- }
- },
Add Comment
Please, Sign In to add comment