Note that there are some explanatory texts on larger screens.

plurals
  1. POCall a javascript function from the activity?
    text
    copied!<p>How can I call a function in a HTML doc that is loaded into a webView with a button that is in my activity? ie: An ImageButton (called: bookBtn) is in the title bar of the activity. When it is pressed/tapped, I need it to fire a function in the webView DOM - It basically loads a new HTML doc into the DOM implementing a slide-in effect. </p> <p>I found plenty of documentation on how to do this from the webView to the activity but not the other way around. Google says it <a href="http://developer.android.com/resources/articles/using-webviews.html" rel="nofollow">can be done</a> but there really isnt any examples. I tried to tweek the example code they show <a href="http://code.google.com/p/apps-for-android/source/browse/trunk/Samples/WebViewDemo/src/com/google/android/webviewdemo/WebViewDemo.java" rel="nofollow">here</a> but I cant get it to work. Thank for any input.</p> <p>Below is the function w/in the HTML doc that is loaded into the webView, mWebView:</p> <pre><code> &lt;script type="text/javascript"&gt; $(document).ready(function() { function loadTOC(){$.mobile.changePage("docs/1-1.html", "slideup"); }; }); &lt;/script&gt; </code></pre> <p>...and w/in my main activity, I tried this as per Google docs but doesn't work:</p> <pre><code> ImageButton imageButton = (ImageButton) findViewById(R.id.bookBtn); imageButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mHandler.post(new Runnable() { public void run() { mWebView.loadUrl("javascript:loadTOC"); } }); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload