I assembled bits and pieces of various approaches and got this to work:
var customEvent = document.createEvent('HTMLEvents');
customEvent.initEvent('myCustomEvent', true, true);
document.dispatchEvent(customEvent);
To be honest, this doesn't make a lot of sense to me. It creates an event (naming it HTMLEvents
seems to be required) on the document, then goes and initializes that event with another name. If anyone can explain this better please add a comment below so it can be incorporated into the answer.
In any case, I'm able to listen to this custom event in IE11 (and modern browsers) with a standard event listener:
document.addEventListener('myCustomEvent', function(){
console.log('Event received.');
});