I need to trigger Enter Key Press event in IE9 using JS. Just like the below code that works for Chrome:
var evsat = document.createEvent('Event');
evsat.initEvent('keypress');
evsat.keyCode = 13;
elem.dispatchEvent(evsat);
createEvent('Event')
is not supported in IE, throws:
"Object doesn't support property or method 'createEvent'"
Please suggest me some other workaround.
UPDATE: How to handle ENTER event in the code below?
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent
(function() {
if (typeof window.CustomEvent === "function") return false; /*If not IE */
function CustomEvent(event, params) {
params = params || {
bubbles: false,
cancelable: false,
detail: undefined
};
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
})();