You don't say why you want to do this, so answers can only address the specific question of "how to tell if a string is an 'on' event".
I don't think there's a definitive strategy for that. Using a list of all possible event types collated from implementations, standards or specifications might be reasonably reliable but will not be perfect since javascript implementations are free to introduce any new type of event they wish. So the list would need to be updated frequently and you'd have to at least test and possibly update the list on every new browser and version that is released. Also, all events may not be supported by all browsers.
Using strategies like collecting the enumerable "on" properties of a DOM object or it's prototype also don't suit since hosts aren't required to implement inheritance on DOM objects and some don't make them enumerable (such as Safari v9 at least).
Another solution is to see if 'on' + string
is a standard property of a DOM object, so:
function isPossibleEventName(s) {
var div = document.createElement('div');
return ('on' + s) in div;
}
['click','input','blur','foo','bar','paste'].forEach(function(s){
document.write('<br>Possible event ' + s + ': ' + isPossibleEventName(s));
});
That will at least tell you if the host supports a particular event type, however it may need to be tested on different element types since not all elements necessarily support all events. Also, it doesn't tell you if the string might be an "on" event in some other host (but neither will collating "on" properties of an element's prototype).
While this should work in all browsers, there is some doubt if the above will work in older Firefox. However, this post says otherwise and it seems OK in version 43. You should test versions back as far as you think reasonable.