I am using backbone,marionette
for my Application.I used same code for both desktop and mobile
but keypress
not working in mobile
.I made a Jsfiddle for testing.
If you open this link in mobile
event not firing,If you open in desktop
it's firing.How can I resolve this.
can anyone help me.
Thanks.
Chrome mobile doesn't support keypress events properly for now. There is a long standing bug for this:
https://code.google.com/p/chromium/issues/detail?id=118639
I believe it should be fixed in v38. The bug report was closed as "won't fix".
I will suggest two events on input box.
This will work on desktop webbrowser.
1) onkeypress = return isNumberKey(event);
function isNumberKey(e)
{
var evt = e || window.event;
if(evt)
{
var charCode = evt.keyCode || evt.which;
}
else
{
return true;
}
if((charCode > 47 && charCode < 58) || charCode == 9 || charCode == 8 || charCode ==46 || charCode ==37 || charCode==39)
{
return true;
}
return false;
}
This will work for mobile
2) onkeyup="numberMobile(event);"
function numberMobile(e){
e.target.value = e.target.value.replace(/[^\d]/g,'');
return false;
}
Apply both event on the input box and it will work.Only drawback is,It make it slow.But for now we have to live with it.
There is one issue woth this solution.Left navigation is not working.I will update more appropriate solution soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With