JS Problem of Android using Web loading Web page

Source: Internet
Author: User

Android has not been used for a long time, use it to pack a HTML5 game, the code is as follows


protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        WebView webview=new WebView (this);     Webview.loadurl ("http://www.girl4493.cn/");//Add this sentence to the webview.setwebviewclient (new Mywebviewclient ()); }

Use when found that all JS can not be used to find a half-day finally know where the problem, using WebView default is the JS off, so it will not execute the JS code, this time only need to add a word to suffice



Webview.getsettings (). Setjavascriptenabled (true);//Support JS

Yes, this sentence is enough, true indicates that the support JS false means that does not support JS, default is not supported, the pattern AH


The complete code is as follows:


package activity.ysmall.cc.ysmall;import android.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);//Support js         webview.loadurl ("http://www.girl4493.cn");         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&nbsP Androidmanifest.xml.        int id = item.getitemid ();         //noinspection SimplifiableIfStatement         if  (id == r.id.action_settings)  {             return true;         }        return super.onoptionsitemselected (item);     }}

With June



This article is from the "Yang Technical column" blog, please be sure to keep this source http://13438626.blog.51cto.com/13428626/1980441

JS Problem of Android using Web loading Web page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.