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.
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.
Share Improve this question asked Dec 24, 2014 at 23:56 JohnnyCageJohnnyCage 1751 gold badge1 silver badge11 bronze badges 1-
4
Do not sniff browsers!
if (document.createEvent)
– epascarello Commented Dec 25, 2014 at 0:50
1 Answer
Reset to default 11Your problem is that fireEvent shouldn't be used in newer IE versions. Support for dispatchEvent was added in IE9. http://help.dottoro./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);
}