title: Uncaught ReferenceError: function is not defined when trying to access in Android webview
body: <p>I am using WebView in Android. I am using loadDataWithBaseURL to load url below:</p>
  
  <p>( here I use "XXXX" to replace my actual webpage URL for security reason )</p>
  
  <p>wb.loadDataWithBaseURL("<a href="http://XXXX.html" rel="nofollow">http://XXXX.html</a>", formattedHTML, "text/html", "UTF-8", null);</p>
  
  <p>The content of formattedHTML contains the actual html source code populated by my service class.</p>
  
  <p>the complete source code of <a href="http://XXXX.html" rel="nofollow">http://XXXX.html</a> is below:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
  
          &lt;script language="javascript"&gt;
              function displayAlert()
              {
                  alert("this is in function displayAlert()");
              }
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body onload="displayAlert();"&gt;dummy
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And I have a button. When it is clicked, I would like to have the javascript function "displayAlert" executed:  wb.loadUrl("javascript:displayAlert()");    </p>
  
  <p>My problem:</p>
  
  <ol>
  <li>I meet with this error message in logCat view: Uncaught SyntaxError: Unexpected identifier at <a href="http://XXXX.html:1" rel="nofollow">http://XXXX.html:1</a>.</li>
  </ol>
  
  <p>I searched quite a lot web pages and most of them said this is caused by the unmatch "{" and "}" in the javascript. But I checked mine and found my javascript code has correct format, as you see above.</p>
  
  <ol start="2">
  <li>When I click the button, the javascript is failed to be executed. Error message:  E/Web Console(534): Uncaught ReferenceError: displayAlert is not defined at null:1.</li>
  </ol>
  
  <p>I have already enabled javascript in webview via:</p>
  
  <pre><code>WebSettings webSettings = wb.getSettings();
  webSettings.setJavaScriptEnabled(true);
  </code></pre>
  
  <p>Why the javascript function implemented in "<a href="http://XXXX.html" rel="nofollow">http://XXXX.html</a>" cannot be located for execution?</p>
  
  <p>Would you please kindly help me? Thanks a lot!</p>