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

  • Home
  • SEARCH
  • 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 6592423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:33:09+00:00 2026-05-25T17:33:09+00:00

I have an Android WebView. I pass HTML to it (as a String). This

  • 0

I have an Android WebView. I pass HTML to it (as a String). This HTML contains some basic javascript.

Upon load, the HTML attempts to call a javascript function (defined in the <head></head>). This works fine in my browser desktop so I’m sure the HTML/Javascript itself is fine, but it fails to work when I load the same HTML into my WebView.

Here is how I instantiate the WebView:

WebView view = new WebView(context);
WebSettings settings = view.getSettings();
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(false);
view.setWebChromeClient(new CustomWebChromeClient());
view.setWebViewClient(new CustomWebViewClient());
view.loadData(ARBITRARY_HTML, "text/html", "utf-8");

The loaded HTML is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>My head hurts from head-desking</title>
    <style type="text/css">
    #content
    {
        display: none;
    }
    </style>
    <script type="text/javascript">
    //<!--
    function ShowContent()
    {
        document.getElementById('content').style.display = 'block';
    }
    //-->
    </script>
</head>
<body onload="ShowContent()">
    <div id="content">
    This content should be shown, but isn't!
    </div>
    <div id="other">
    All I see is this content... and that makes me question my self worth.
    </div>
</body>
</html>

This produces (on Android only) the runtime javascript error: “Uncaught ReferenceError: ShowContent is not defined”.

  • 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-05-25T17:33:10+00:00Added an answer on May 25, 2026 at 5:33 pm

    I have an assumption. The //<!-- ... //--> technique which is a made up hack for really old browsers is so out of date. Try to remove that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webview that has some custom HTML loaded into it. In this
I am working on some javascript injection into m android webview. I am just
I have webview, and I'm using geo-location feature in android. I'm using javascript (onload)
I have an android listview filled with items. Every item has a button. This
I'm using Android, and I've created a Webview which nicely opens my HTML page
I have an Android application that is a TabHost with a WebView. I use
I'd like to add a context menu on an entire Android WebView. I have
I have a WebView that I'm using to open some files stored in the
I have seen lot of threads about loading a PDF in Android Webview. But
I have a Android 2.1 application with a WebView. In that WebView I want

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.