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

OnCreate (Bundle savedinstancestate) {        Super. OnCreate (savedinstancestate); WebView webview=WebView (this);        Webview.loadurl ("http://www.mimi199.com/");
Plus this sentence will be able to        webview.setwebviewclient (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:

 PackageActivity.ysmall.cc.ysmall;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.webkit.WebView;Public classMainactivityextendsactionbaractivity {@Overrideprotected voidOnCreate (Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); WebView webview=NewWebView ( This); Webview.getsettings (). setjavascriptenabled (true);//Support JSWebview.loadurl ("http://www.mimi199.com/"); Webview.setwebviewclient (NewMywebviewclient ()); } @OverridePublic BooleanOncreateoptionsmenu (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; } @OverridePublic BooleanOnoptionsitemselected (MenuItem Item) {//Handle Action Bar item clicks here. The Action Bar would//automatically handle clicks on the Home/up button, so long//As you specify a parent activity in Androidmanifest.xml.intid = item.getitemid ();//noinspection simplifiableifstatementif(id = = R.id.action_settings) {return True; }return Super. onoptionsitemselected (item); }}

With June

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.