@mongodb-js/mongodb-ui-components
Version:
A collection of frequently used functional UI components found on mongodb properties
39 lines (28 loc) • 908 B
JavaScript
;
module.exports = clipboardCopy;
function clipboardCopy(text, removeStyle) {
const span = document.createElement('span');
span.textContent = text;
span.style.whiteSpace = 'pre';
const iframe = document.createElement('iframe');
iframe.sandbox = 'allow-same-origin';
document.body.appendChild(iframe);
const win = iframe.contentWindow;
win.document.body.appendChild(span);
const selection = win.getSelection();
const range = win.document.createRange();
let success = false;
try {
selection.removeAllRanges();
range.selectNode(span);
selection.addRange(range);
success = win.document.execCommand('copy');
} catch (err) {}
selection.removeAllRanges();
iframe.remove();
return success;
}
clipboardCopy.isSupported = function () {
if (document.queryCommandSupported && document.queryCommandSupported('copy')) return true;
return false;
};