]> git.ardis.lu - event-hashes/commitdiff
Add clipboard.writeText fallback for Firefox
authorArdis Lu <ardisglu@gmail.com>
Sun, 17 Mar 2024 04:16:04 +0000 (21:16 -0700)
committerArdis Lu <ardisglu@gmail.com>
Sun, 17 Mar 2024 04:16:04 +0000 (21:16 -0700)
index.html

index 68a8b6c66511cf77ec2953bba3990f6d3780153a..d02febcabb249f4bec151ff7998f450005a020b9 100644 (file)
 
     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');
     });
 
This page took 0.036125 seconds and 4 git commands to generate.