0

OnKeyPress is not being called in android webview... My Html code is simple

<input type="number" onkeypress="myFunc()"/>

function myFunc(){
alert(fired up!);
}

All the other keyevents i.e keyup, keydown are working.

Syed Wajahat Ali
  • 541
  • 1
  • 7
  • 25
  • @RemeesMSyde My code is so simple there is a textbox with attached keypress event all the other events like onkeyup/down are working but not this one – Syed Wajahat Ali Dec 02 '14 at 06:18
  • Are you sure that this "alert" is working fine? Check this link [JavaScript alert not working in Android WebView][1] [1]: http://stackoverflow.com/questions/5271898/javascript-alert-not-working-in-android-webview – Marc LaQuay Dec 02 '14 at 07:50
  • Yes alerts are working fine its just the keypress event that's not working – Syed Wajahat Ali Dec 02 '14 at 07:57

2 Answers2

0
  • Try to use WebChromeClient for loading it.
  • Try to build with lower version. Because in latest version API 17 and above they added JavascriptInterface. You need to include this as a seperate class that extends JavascriptInterface.

    To reduce application compatibility try to build with 16 or below.
rasfarrf5
  • 219
  • 1
  • 5
0

Android Webview really doesn't fire onkeypress event (even on newer versions of Android).

One posible solution is to replace it with onkeyup or onkeydown, like this:

<input type="number" onkeyup="myFunc()"/>

function myFunc(){
   alert(fired up!);
}