Is IE8 your new IE6? Level the playing field with polyfills.
Is IE6 still your IE6? You're covered too now.
This script polyfills addEventListener, removeEventListener, dispatchEvent, CustomEvent, and DOMContentLoaded. It is less than half a kilobyte minified and gzipped.
addEventListener registers an event listener on a target.
target.addEventListener(type, listener);
-
type: A string representing the event type to listen for.
-
listener: The object that receives a notification when an event of the specified type occurs. This must be an object implementing the EventListener interface, or simply a JavaScript function.
It should be noted that useCapture has not been polyfilled.
removeEventListener unregisters an event listener on a target.
target.removeEventListener(type, listener);
-
type: A string representing the event type being removed.
-
listener: The EventListener object or function to be removed.
It should be noted that useCapture has not been polyfilled.
Dispatches an event into the event system. The event is subject to the same capturing and bubbling behavior as directly dispatched events.
bool = target.dispatchEvent(event);
- event: An event object to be dispatched.
It should be noted that document.createEvent
has not been polyfilled.
A custom event to be initialized by dispatchEvent.
var event = new CustomEvent(type, canBubble, cancelable, details);
-
type: A string representing the event type.
-
canBubble: A boolean indicating whether the event bubbles up through the DOM or not.
-
cancelable: A boolean indicating whether the event is cancelable.
-
details: Additional data passed into the custom event.