I put a webview in my application to visit a webpage which includes some javascript functions, my purpose is when users click a link in the webpage, it will start a new activity in the application. I've written "webSettings.setJavaScriptEnabled(true);" in my source codes.
It works well in most of the time, however sometimes it doesn't work, there is no response when users click, and I don't know why because the environment is not changed at all. Has anybody know why?
Enable JavaScript JavaScript is disabled in a WebView by default. You can enable it through the WebSettings attached to your WebView . You can retrieve WebSettings with getSettings() , then enable JavaScript with setJavaScriptEnabled() . WebView myWebView = (WebView) findViewById(R.
Can we use JavaScript for Android? Yes, of course! The Android ecosystem supports the concept of hybrid apps, which is a wrapper over the native platform.
Alternatives to WebView If you want to send users to a mobile site, build a progressive web app (PWA). If you want to display third-party web content, send an intent to installed web browsers. If you want to avoid leaving your app to open the browser, or if you want to customize the browser's UI, use Custom Tabs.
I read about how to increase performance of WebView by implementing Caching web resources like JS, CSS and image files. You can also static resources in your native application, and by intercepting the Resource requests you can override the default behaviour of WebView.
v.setWebChromeClient(new WebChromeClient() {
@Override
public void onConsoleMessage(String message, int lineNumber,String sourceID) {
Log.d("MyApplication", message + " -- From line "+ lineNumber + " of " + sourceID);
super.onConsoleMessage(message, lineNumber, sourceID);
}
});
check this code so at least you will get error message and one more thing is that android doesn't supports all JavaScript functions.
I had the same issue. I changed the event for from 'click' to 'touchstart' and now its awesome.
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