-
-
Save JamesMGreene/8597596 to your computer and use it in GitHub Desktop.
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
var btn = document.getElementById("copy-button"); | |
btn.addEventListener("click", clickHandler, false); | |
function clickHandler(e) { | |
var clip = new ClipboardEvent("copy"); | |
clip.clipboardData.setData("text/plain", "foo"); | |
clip.clipboardData.setData("text/html", "<b>foo</b>"); | |
// CRITICAL: Must call `preventDefault();` to get this data into the system/desktop clipboard!!! | |
clip.preventDefault(); | |
e.target.dispatchEvent(clip); | |
} |
Good catch, thanks! Fixed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fix clip.setData to clip.clipboardData.setData() :-)