Created
March 23, 2019 02:46
-
-
Save dguo/29b89d58c887aa17450e8539fa26e4e0 to your computer and use it in GitHub Desktop.
blog - How to Add Copy to Clipboard Buttons to Code Blocks in Hugo - check-clipboard
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 characters
if (navigator && navigator.clipboard) { | |
addCopyButtons(navigator.clipboard); | |
} else { | |
var script = document.createElement('script'); | |
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/clipboard-polyfill/2.7.0/clipboard-polyfill.promise.js'; | |
script.integrity = 'sha256-waClS2re9NUbXRsryKoof+F9qc1gjjIhc2eT7ZbIv94='; | |
script.crossOrigin = 'anonymous'; | |
script.onload = function() { | |
addCopyButtons(clipboard); | |
}; | |
document.body.appendChild(script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment