Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView Javascript enabled

Tags:

android

activity_main.xml

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView webView =(WebView)findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.loadUrl("file:///android_asset/www/index.html");
}

i have this code, but javascript is not working :(

like image 654
KAKHA13 Avatar asked Dec 15 '12 01:12

KAKHA13


People also ask

What is JavaScript WebView?

Web view acts as an in-built browser which displays the webpages in Android. In other words, Web view turns your application into web application. WebView is an extension of Android's View class. It uses WebKit to display a web page which is a browser engine which provides tools for browsing the web.

How do I enable JavaScript on my HTML viewer?

Enabling JavaScript in Android BrowserIn the Browser window, click on the menu icon with three vertical lines. Then tap on Settings from the dropdown list. Click on the Advanced button, where you will see Enable JavaScript on the list. Finally, click on the box next to Enable JavaScript to turn it on.

How do I change WebView settings on Android?

May 18, 2021•HSM ArticleGo to settings > apps and select Chrome application. Tap on Disable (this will disable the chrome browser) Go to Google PlayStore and search for webview. Tap on Android System Webview in the search results.


1 Answers

You've forgot one of the most important ones :

webView.getSettings().setPluginState(PluginState.ON);
like image 70
Ceetn Avatar answered Oct 29 '22 10:10

Ceetn