I try to find a way to check if an eventListener already exists in a window, I've tried the solution in this similar question and more other solutions, but nothing works for me.
Here is the code:
checkEvent=function()
{
if('keydown' in window)
console.log('exist');
else
console.log('not_exist');
}
And here is my eventListener that I add on my page Load
document.addEventListener("keydown", PayKeydownHandler);
But the first code, returns 'not_exist' as a result
PS: The function checkEvent(), i call it in onclick of ENTER keydown.
Any help please? Thank's in advance.
window, but you add the event listener todocument. Second, if you're only going to add one listener, you could probably just directly set theonkeydownproperty and then havecheckEventcheck if that property is set to a function. Otherwise, I don't believe there's a built in way to do this.