title: Android WebView.loadDataWithBaseURL() JavaScript Injection Question
body: <p>I have searched high and low for a solution to this problem, and while I found one question, I have found zero responses.  I'll lay out the entire situation because maybe there's a solution I'm not seeing...</p>
  
  <p>I have an HTML file loaded on to the user's SD card.  I'm loading that HTML file into a WebView using WebView.loadURL(...).  This works fine.  That HTML imports external Javascript files like so:</p>
  
  <pre><code>&lt;script type='text/javascript' src='js/jquery-1.3.2.min.js' /&gt;
  &lt;script type='text/javascript' src='js/inPractice-utilities.js' /&gt;
  &lt;script type='text/javascript' src='js/inPractice.js' /&gt;
  &lt;script type='text/javascript' src='js/mobile/inpractice.ipad.js /'&gt;
  </code></pre>
  
  <p>Of course, this does not work because after SDK 1.0, the ability load this external code was deemed a security issue (or at least that's how I understood it).  I changed each HTML file (there are hundreds) to use inline Javascript, and all works fine.</p>
  
  <p>Each HTML file has links that call Javascript methods using their "onClick" event.</p>
  
  <pre><code>&lt;a href="/drug" onclick="return content('drug', {name:'Tamoxifen', pageId:'9475b30a-5a8b-04fa-f975-7fcaeaa0a2cf'});"&gt;Tamoxifen&lt;/a&gt;
  </code></pre>
  
  <p>As you can see, the javascript method, "content", is called when the user clicks on this link.  This also works fine.</p>
  
  <p>However, some files have links to "supporting assets", which are essentially separate HTML pages themselves, except without the actual page.  Here's an example:</p>
  
  <pre><code>&lt;a href="/supportingAsset" onclick="return content('supportingAsset', {'html':'&lt;div class='supportingAsset'&gt;&lt;p&gt;&lt;a href='/drug' onclick='return content('drug', {name:'Tamoxifen', pageId:'9475b30a-5a8b-04fa-f975-7fcaeaa0a2cf'});'&gt;Tamoxifen&lt;/a&gt;'});"&gt;Supporting Asset&lt;/a&gt;
  </code></pre>
  
  <p>*Note, there may be some syntax issues in my recreation, but I promise the syntax is all correct in the actual code.</p>
  
  <p>So, the issue here is that the supporting asset HTML is included as a parameter to the call to Javascript method "content".  In order to display this content when the user clicks on the supporting asset, I use...</p>
  
  <pre><code>webView.loadDataWithBaseURL("file://" + baseLocation, html, "text/html", "utf-8", null);
  </code></pre>
  
  <p>...where "html" is the HTML passed into the Javascript method, "content".  This new page is displaying fine, BUT...if you notice in the supporting asset content, there is ANOTHER link that calls out to the Javascript method, "content".  This is where the problem lies...</p>
  
  <p>I've tried appending...</p>
  
  <pre><code>&lt;script type='text/javascript' src='js/jquery-1.3.2.min.js' /&gt;
  </code></pre>
  
  <p>...to the raw HTML before loading it into the webview. Nothing.</p>
  
  <p>I've tried appending the inline Javascript method. Nothing.</p>
  
  <p>I've tried adding the Javascript method after pageLoad...</p>
  
  <pre><code>    @Override
      public void onPageFinished(WebView view, String url) {
          if (loadingPageDialog != null) {
              loadingPageDialog.dismiss();
          }
  
          view.loadUrl("javascript:(function content(path, params) { " +  
                  "document.getElementsByTagName('body')[0].style.color = 'red'; " +  
          "})()");  
      }
  </code></pre>
  
  <p>...Nothing.</p>
  
  <p><b>Actual Question</b></p>
  
  <p>Does anyone know of a way I can inject the Javascript method "content", such that the existing call to "content" works?  Note, I can't change the call to "content", and the webview that displays the supporting asset content is in a separate activity from the original webview. </p>