We have a datepicker (in JavaScript) that has a section for checking IE 8 and older and other modern browsers.
if(-1 != navigator.userAgent.indexOf("MSIE")){
obj_caller.target.fireEvent("onchange");
}
else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
obj_caller.target.dispatchEvent(evt);
}
It's working fine in Chrome, Firefox, IE8 and below but is failing in IE 11. What I need is a way to get the else part working in IE 11. I just cannot figure out what is failing and how to fix it.
Thanks.
dispatchEvent () is the last step of the create-init-dispatch process, which is used for dispatching events into the implementation's event model. The event can be created using Event constructor . See also the Event object reference. See Creating and triggering events.
Document Object Model (DOM) Level 3 Events Specification, Section 4.3 Events that the IEventTarget::dispatchEvent method dispatches are subject to the same capturing and bubbling behavior as events that the browser dispatches. You cannot cancel some events. For more information, see the documentation for the event.
You cannot dispatch an internal event. Document Object Model (DOM) Level 3 Events Specification, Section 4.3 Events that the IEventTarget::dispatchEvent method dispatches are subject to the same capturing and bubbling behavior as events that the browser dispatches. You cannot cancel some events.
For more information, see the documentation for the event. In general, events can only be dispatched from elements that are part of the document object model, per the HTML5 specification.
Your problem is that fireEvent shouldn't be used in newer IE versions. Support for dispatchEvent was added in IE9. http://help.dottoro.com/ljrinokx.php
if(document.createEventObject) {
obj_caller.target.fireEvent("onchange");
} else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
obj_caller.target.dispatchEvent(evt);
}
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