Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:54:32+00:00 2026-06-10T19:54:32+00:00

WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setPluginsEnabled(true); myWebView.loadUrl(file:///android_asset/index.html); myWebView.loadUrl(javascript:hello()); It

  • 0
WebView myWebView = (WebView) findViewById(R.id.webview);                
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setPluginsEnabled(true);        
    myWebView.loadUrl("file:///android_asset/index.html");
    myWebView.loadUrl("javascript:hello()");

It doesnt work in 4.0 emulator or real device. I have proper tag in html like

<script type="text/javascript">..</script>

and i can fire it from firefox’s console with no problem (it doesnt call alert command, i know it doesnt work in android)

I am out of solutions, please help me.

Btw this function call seems useless here because it is for testing, i will give a parameter later if this works.

Edit:

<h1 id="title"></h1>
....

<script type="text/javascript">
function hello()
{
  console.log("hello"); 
  var title = document.getElementById("title");
  title.innerHTML = "hello";    
}
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:54:34+00:00Added an answer on June 10, 2026 at 7:54 pm

    The problem is that there is no guarantee that the page has been loaded when you call the javascript. Make sure that you call the javascript function only when the page is completely loaded.

    The following code (quoted from http://lexandera.com/2009/01/injecting-javascript-into-a-webview/) will give you a heads up.

    final WebView webview = (WebView)findViewById(R.id.browser);
    /* JavaScript must be enabled if you want it to work, obviously */
    webview.getSettings().setJavaScriptEnabled(true);
    
    /* WebViewClient must be set BEFORE calling loadUrl! */
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url)
        {
            webview.loadUrl("javascript:(function() { " +
                    "document.getElementsByTagName('body')[0].style.color = 'red'; " +
                    "})()");
        }
    });
    
    webview.loadUrl("http://code.google.com/android");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code : getWindow().requestFeature(Window.FEATURE_PROGRESS); WebView mWebView = (WebView) findViewById(R.id.mywebview); mWebView.getSettings().setJavaScriptEnabled(true); final Activity
My Webview setting for now is.. wv = (WebView) findViewById(R.id.webView1); wv.setHorizontalScrollBarEnabled(true); wv.setKeepScreenOn(true); wv.getSettings().setJavaScriptEnabled(true); wv.getSettings().setBuiltInZoomControls(true);
I am loading a WebView in an Android application with the below code: mWebView.loadURL(https://wat.harminson.com/html/index.html);
I have placed following javascript in my html file. <script TYPE=text/javascript> function srk(){ document.ontouchmove
I have a simple webview used to load a file help3.html when a user
xml <?xml version=1.0 encoding=utf-8?> <WebView xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/myWebView android:layout_width=wrap_content android:layout_height=wrap_content /> java public void onCreate(Bundle
I used webView to show javaScript,one image was included in the javaScrip,but the webView
Hi I am trying to load a webview that uses javascript and html5. However,
I am getting this strange error: R.id cannot be resolved on lines: WebView myWebView
Possible Duplicate: JavaScript alert not working in Android WebView I am developing an app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.