diff --git a/src/scripts/clipboard.js b/src/scripts/clipboard.js index efa465823a..7e7170b7a1 100644 --- a/src/scripts/clipboard.js +++ b/src/scripts/clipboard.js @@ -1,3 +1,5 @@ +import browser from './browser'; + /** * Copies text to the clipboard using the textarea. * @param {string} text - Text to copy. @@ -8,7 +10,20 @@ function textAreaCopy(text) { textArea.value = text; document.body.appendChild(textArea); textArea.focus(); - textArea.select(); + + // iOS 13.4 supports Clipboard.writeText (https://stackoverflow.com/a/61868028) + if (browser.iOS && browser.iOSVersion < 13.4) { + // https://stackoverflow.com/a/46858939 + + const range = document.createRange(); + range.selectNodeContents(textArea); + const selection = window.getSelection(); + selection.removeAllRanges(); + selection.addRange(range); + textArea.setSelectionRange(0, 999999); + } else { + textArea.select(); + } let ret;