js problem of android using web to load webpage

Android has not been used for a long time, use it to package a beautiful picture , the code is as follows

 

 

 

protected void onCreate(Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);

WebView webView=new WebView(this);

        webView.loadUrl("http://www.mimi199.com/);

// just add this sentence

        webView.setWebViewClient (new MyWebViewClient ());

 

     }

When I used it, I found that all the js could not be used. After looking for a long time, I finally knew where the problem was. When using webview by default, js is turned off, so the js code will not be executed. At this time, it is enough to add a sentence.

 

 

 

 

 

webView.getSettings().setJavaScriptEnabled(true);//支持js

Yes, this sentence is enough, true means js is supported false means js is not supported, the default is not supported, the pattern

 

 

 

The complete code is as follows:

 

 

 

package www,mimi199.com

 

importandroid.support.v7.app.ActionBarActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.webkit.WebView;

 

 

public class MainActivity extends ActionBarActivity {

 

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate (savedInstanceState);

         WebView webView=new WebView(this);

        webView.getSettings().setJavaScriptEnabled(true);//支持js

webView.loadUrl("http://www.mimi199.com/");

        webView.setWebViewClient (new MyWebViewClient ());

 

 

    }

 

 

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        // Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

        return true;

    }

 

    @Override

    public boolean onOptionsItemSelected(MenuItem item) {

        // Handle action bar item clicks here. The action bar will

        // automatically handle clicks on the Home/Up button, so long

        // as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

 

        //noinspection SimplifiedIfStatement

if (id == R.id.action_settings) {

            return true;

        }

 

        return super.onOptionsItemSelected(item);

    }

}

share with you

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326128455&siteId=291194637