Android Webview + WebViewClient + javascript + hardware input
I've a webview which should distinguish between internal site links and external links. I achieve this behavior by adding a html anchor named "#external" to every link url which contains html-attribute target="_blank" with the help of javascript and checking the urls with WebViewClient's
开发者_如何学CshouldOverrideUrlLoading
This solution works great as long as the user selects a link on the touchscreen. If the user selects a link with a hardware input method (e.g. scroll-ball or enter-key) the html anchor is missing from the request url and as a result my external link detection won't work.
Any ideas of what's going wrong?
Thx in advance, alex
I got the same behaviour on my app, and it gets worse when you need to use javascript on the pages (if you click on a link with the trackball, the event may not get passed to any javascript listeners).
I found two solutions:
1 - Do not use the shouldOverrideUrlLoading function, since if you use it, javascript won't work with the trackball events. You can work with the onPageStarted and onPageFinished methods, BUT android may open a browser everytime you touch a link, so you will need some creative javascript work to work around that.
2- Completelly disable the trackball if you intend to use a webview with some javascript and still use shouldOverrideUrlLoading.
@Override
public boolean onTrackballEvent (MotionEvent event)
{
return true;
}
My app has number 2.
精彩评论