From a3a2d49973c41f0037a5d50f3281a3c3ec056277 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 16 Mar 2024 21:16:04 -0700 Subject: [PATCH] Add clipboard.writeText fallback for Firefox --- index.html | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 68a8b6c..d02febc 100644 --- a/index.html +++ b/index.html @@ -405,11 +405,16 @@ document.querySelector('#copy-table').addEventListener('click', async e => { const table = document.querySelector('table'); - const data = [new ClipboardItem({ - 'text/plain': new Blob([table.innerText], { type: 'text/plain' }), - 'text/html': new Blob([table.outerHTML], { type: 'text/html' }) - })]; - navigator.clipboard.write(data); + if (window.ClipboardItem === undefined) { + navigator.clipboard.writeText(table.innerText); + } + else { + const data = [new ClipboardItem({ + 'text/plain': new Blob([table.innerText], { type: 'text/plain' }), + 'text/html': new Blob([table.outerHTML], { type: 'text/html' }) + })]; + navigator.clipboard.write(data); + } debounceButton(e.target, clipboardSVG, 'Copy table to clipboard'); }); -- 2.47.3