From fe470820b8667a5db7d08b670122a06c784a67d6 Mon Sep 17 00:00:00 2001 From: Aaron Ortbals Date: Tue, 2 Jul 2019 19:18:30 -0500 Subject: [PATCH] fix: copy sometimes does not work due to the selection command failing - remove the existing range before the copy command --- index.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index 8b84585..854e2ec 100644 --- a/index.html +++ b/index.html @@ -27,7 +27,7 @@ margin: 0; padding: 74px 0 0; box-sizing: border-box; - background: dimgray; + background: dimgray; background-attachment: fixed; background-size: cover; display: flex; @@ -92,7 +92,7 @@ align-items: center; padding-bottom: 18px; margin-bottom: 21px; - border-bottom: 1px solid var(--primary-color); + border-bottom: 1px solid var(--primary-color); text-align: left; } form { @@ -302,11 +302,12 @@

My Ipsum

document.getElementById('refresh').onclick = fetchMore document.getElementById('expand').onclick = toggleExpanded document.getElementById('copy').addEventListener('click', function(event) { - var range = document.createRange() - range.selectNode(document.getElementById('ipsum')) - window.getSelection().addRange(range) - try { + var range = document.createRange() + range.selectNode(document.getElementById('ipsum')) + var selection = window.getSelection() + selection.removeAllRanges() + selection.addRange(range) var successful = document.execCommand('copy') if (successful) { document.getElementById('copy').innerText = "Copied!"