N
N
nikita_chiru2016-12-28 21:45:52
JavaScript
nikita_chiru, 2016-12-28 21:45:52

How to make webview run javascript?

Opens the page in a webview located on the server, but the javascript does not work. Tell good people

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        WebView myWebView = (WebView) findViewById(R.id.webBrowser);

        WebSettings webSettings = myWebView.getSettings();

        webSettings.setJavaScriptEnabled(true);
        myWebView.setWebViewClient(new WebViewClient());
        myWebView.loadUrl("http:Моя ссылка);
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rou1997, 2016-12-28
@Rou1997

Should work, where did you get the idea that it does not work at all? If it does not work alert, etc., this is a separate problem.

D
Dmitry Alexandrov, 2016-12-29
@jamakasi666

What version of android? What version of webview on android? What SDK version are you using? What makes you think that js does not work? Checking on a simple page with a simple js script is not fate to make sure that it definitely does not work?
Transfer:

webSettings.setJavaScriptEnabled(true);
myWebView.setWebViewClient(new WebViewClient());
WebSettings webSettings = myWebView.getSettings();

Try to hook up WebChromeClient to enable the maximum number of js functions for sure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question