首页 > 编程语言 > 详细

android使用web加载网页的js问题

时间:2017-11-09 15:36:03      阅读:364      评论:0      收藏:0      [点我收藏+]

android好久没有用了,用它来打包个美女图片,代码如下

 

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
WebView webView=new WebView(this);
        webView.loadUrl("http://www.mimi199.com/);
	//多加上这句话就可以了
        webView.setWebViewClient(new MyWebViewClient());

     }

使用时发现所有的js都无法使用来,找来半天终于知道问题在哪里了,使用webview默认是吧js关闭的,因此是不会执行js代码的,这个时候只需要加上一句话就够了

 

 

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

是的,这句话就够了,true表示支持js false表示不支持js,默认是不支持的,图样啊

 

完整代码如下:

 

package activity.ysmall.cc.ysmall; 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 SimplifiableIfStatement if (id == R.id.action_settings) { return true;
        } return super.onOptionsItemSelected(item);
    }
}

与君共勉

android使用web加载网页的js问题

(2)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!