Last active
          August 24, 2024 11:04 
        
      - 
      
- 
        Save n1k0/b17b5c248a3ee1df99acaae000eccae4 to your computer and use it in GitHub Desktop. 
Revisions
- 
        n1k0 revised this gist Jul 9, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ return res; }); } catch (err) { return Promise.resolve(false); } } } 
- 
        n1k0 created this gist Jul 9, 2018 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>copy to clipboard for chrome and firefox</title> </head> <body> <button>copy</button> <script> function toClipoard(text) { if ("clipboard" in navigator && typeof navigator.clipboard.writeText === "function") { // Chrome return navigator.clipboard.writeText(text) .then(() => true) .catch(() => false); } else { // Firefox const input = document.createElement("input"); input.value = text; input.style.position = "fixed"; input.style.top = "-2000px"; document.body.appendChild(input); input.select(); try { return Promise.resolve(document.execCommand("copy")) .then(res => { document.body.removeChild(input); return res; }); } catch (err) { Promise.resolve(false); } } } document.querySelector("button").addEventListener("click", _ => { toClipoard("this is a test") .then(res => console.log("copied", res)); }); </script> </body> </html>