Or simply, name the parameter event and it will work in all browsers. Here is a jQueryish example:
$('#' + _aYearBindFlds[i]).on('keyup', function(event) { if(! ignoreKey({szKeyCodeList: gvk_kcToIgnore, nKeyCode: event.keyCode })) this.value = this.value.replace(/\D/g, ''); });
This example allows you to enter numbers only for the year fields (inside a for each loop selector), where ingoreKey () takes a keyCode list / array and compares the keyCode event and determines whether to ignore it before triggering the binding event.
The keys that I usually use for masks / others are the arrow, backspace, tabs, depending on the context / desired behavior.
You can usually also use event.which instead of event.keyCode in most browsers, at least when you use jQuery, which depends on event.which to normalize key and mouse events.
I donβt know exactly what is happening under the covers in js machines, but it seems that Mozilla FF respects a more restrictive area in which other browsers can automatically access window.event.keyCode scope on their own when the event is not explicitly passed to the function or close.
In FF, you can also access the event using window.event (as shown in some examples here), which would support this idea.
williambq
source share