Last active
November 5, 2019 07:47
-
-
Save JamesMGreene/8589353 to your computer and use it in GitHub Desktop.
HTML Clipboard API clarification example
This file contains 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); | |
btn.addEventListener("copy", copyHandler, false); | |
function clickHandler(e) { | |
e.target.dispatchEvent(new ClipboardEvent("copy")); | |
} | |
function copyHandler(e) { | |
e.clipboardData.setData("text/plain", "Simulated copy. Yay!"); | |
// CRITICAL: Must call `preventDefault();` to get this data into the system/desktop clipboard!!! | |
e.preventDefault(); | |
} |
Same issue here.
You are not allowed to create constructor on ClipboardEvent in any browser but FF. Please refer to http://caniuse.com/#feat=clipboard
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am getting an uncaught type error: illegal constructor error when I try and use ClipboardEvent.