The following code fails (in javascript console, and also when injecting a script via browser extension)
document.createEvent('TestEvent')
Firebug spits out:
[Exception... "Operation is not supported" 
 code: "9" 
 nsresult: "0x80530009 (NS_ERROR_DOM_NOT_SUPPORTED_ERR)" 
 location: "http://www.google.com 
 Line: 71"] 
Chrome gives a similar error message. What am I doing wrong?
From the documentation:
typeis a string that represents the type of event to be created. Possible event types include "UIEvents", "MouseEvents", "MutationEvents", and "HTMLEvents".
So you probably want:
var e = document.createEvent('HTMLEvents');
e.initEvent('TestEvent', true, true);
See event.initEvent.
Update: Maybe document.createEvent('Event'); is even better for custom events, but it is part of DOM Level 3 and I don't know how much supported it is.
Use one of these event types: https://developer.mozilla.org/en/DOM/document.createEvent#Notes
TestEvent is not a supported event type. Better use "MouseEvents" or "HTMLEvents".
There's simply no event type called TestEvent:
https://developer.mozilla.org/en/DOM/document.createEvent#section_4
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-DocumentEvent-createEvent
Maybe you meant TextEvent?
PS: Next time do at least a bit of own research before using SO like you would use Google ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With