Skip to content

Instantly share code, notes, and snippets.

@luobotang
Created August 23, 2017 08:22
Show Gist options
  • Save luobotang/79f4c5b964fb8dd4ca829a2fa12bc408 to your computer and use it in GitHub Desktop.
Save luobotang/79f4c5b964fb8dd4ca829a2fa12bc408 to your computer and use it in GitHub Desktop.
DispatchCustomEvent
function dispatchCustomEvent(name, data) {
var e;
if (window.CustomEvent) {
e = new window.CustomEvent(name, {
canBubble: true,
cancelable: true,
detail: data
})
} else {
e = document.createEvent('CustomEvent');
e.initCustomEvent(name, true, true, data)
}
document.dispatchEvent(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment