I am loading a webpage in an android Webview which contains a several buttons:
< button id="ID" class="class" type="submit">button lable < /button>
There also exists a javascript which should be triggered when you click the button.
Everything works fine on devices with android older than 4.4 . But on 4.4 it does nothing.
Is there a way to solve this problem and make it work also on android 4.4? if so what is the solution?
Here is the webview cod
private void init() {
webview = (WebView) getView().findViewById(R.id.webview);
webview.clearCache(true);
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
currentUrl = url;
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(startUrl);
}
Here is the javascript which will be called if I click on a button in the webview
{ window.open('<url which should be opened out of the app>');
self.location = "<webviewredirecturl>"; }
According to to my tests, when your project target is kitkat, the loadUrl method behavior changes. Instead of being able to execute load on your current page, it systematically open a new page with your url parameter.
For my case, I was sending this url to my already loaded page webview :
javascript:showComment('Content html to add')
With target API 18 everything is working, with target API 19, error.
More information about changes with kitkat her :
http://www.mobilexweb.com/blog/android-4-4-kitkat-browser-chrome-webview
Similar Post here : Loading javascript functions to webview in Android Kitkat
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.