higlass
Version:
HiGlass Hi-C / genomic / large data viewer
37 lines (31 loc) • 842 B
JavaScript
/** @param {string} text */
function fallbackCopyTextToClipboard(text) {
const textArea = document.createElement('textarea');
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.top = '0';
textArea.style.left = '0';
textArea.style.position = 'fixed';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
} catch (err) {
// console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
}
/** @param {string} text */
export default function copyTextToClipboard(text) {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(text);
return;
}
navigator.clipboard.writeText(text).then(
() => {},
(err) => {
// console.error('Async: Could not copy text: ', err);
},
);
}