-
-
Save djekl/f163efa095cacf41c3dc7a46b2d6938f to your computer and use it in GitHub Desktop.
Revisions
-
stevebauman revised this gist
Aug 17, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This 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 @@ -1,5 +1,5 @@ /** * Copy rich text content to clipboard. * * Must be initiated by a user click event. * -
stevebauman revised this gist
Aug 13, 2021 . 1 changed file with 7 additions and 0 deletions.There are no files selected for viewing
This 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 @@ -1,3 +1,10 @@ /** * Copy the rich text content to clipboard. * * Must be initiated by a user click event. * * @param {string} content */ export default function (content) { const selection = window.getSelection(); -
stevebauman created this gist
Aug 13, 2021 .There are no files selected for viewing
This 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,25 @@ export default function (content) { const selection = window.getSelection(); const range = document.createRange(); range.selectNodeContents(document.body); selection.removeAllRanges(); selection.addRange(range); const listener = (e) => { e.clipboardData.setData("text/html", content); e.clipboardData.setData("text/plain", content); e.preventDefault(); } document.addEventListener("copy", listener); document.execCommand("copy"); document.removeEventListener("copy", listener); selection.removeAllRanges(); }