81
Views
2
Comments
Javascript eventlistener not working
Question

Hi All,

I have an eventlistener added on the OnReady. But it only starts listening when you interacted with the screen (scroll or press somewhere on the screen). If you open the app and don't do anything it's not working. The phone has a hardware button to do an enter. And this is what I try to catch.

Someone already had this issue and has a solution for it?

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

Can you share the Javascript code in the onReady event?

Regards,

Daniel

2018-12-04 15-29-30
Michiel Moens

Hi Daniel,

Sure, here it is:

document.addEventListener("keypress", function _listener(e) {   if(document.querySelector(".Input_barcode") !== null){        

if(e.key == "Enter"){            
input.value = "";            
input.readOnly = true;            
input.focus();            
setTimeout(function(){                 
document.querySelector(".Input_barcode").readOnly = false;            
});            
$parameters.Key = e.key;                   
$actions.BarcodeChange();            
e.preventDefault();        
}    
}});

Best regards,
Michiel

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.