0

I have a webview element containing a jqmath script that I load from an external script in android studio, the function to pass variables into the script looks like this:

void UpdateFunc() {
    js = "<html><head>"
            + "<link rel='stylesheet' href='file:///android_asset/mathscribe/jqmath-0.4.3.css'>"
            + "<script src='file:///android_asset/mathscribe/jquery-1.4.3.min.js'></script>"
            + "<script src='file:///android_asset/mathscribe/jqmath-etc-0.4.3.min.js'></script>"
            + "</head><body>"
            + "<script>var s =   '$$" + functext + "$$';M.parseMath(s);document.write(s);</script> </body>";
    webView.loadDataWithBaseURL("", js, "text/html", "UTF-8", "");
}

I require to run some functions and I have been suggested to extend use WebViewClient and run OnPageFinished(), my code as follows (under OnCreate):

webView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {

            code
        }
    });

The issue is, OnPageFinished gets called before the script finished updating the webview.

Is there any method I could undertake t hat would allow me to run code immediately after the script finished updating the webview? Or how to fix the issue with OnPageFinished? Note also that I did not pass any variables in the function seeing as I have only one webview.

Thanks in advance.

hata
  • 11,633
  • 6
  • 46
  • 69
daedsidog
  • 1,732
  • 2
  • 17
  • 36

1 Answers1

0

See Jqmath - apply after page load

Basically, you call M.parseMath on a DOM element after you've loaded jqMath text into it.

Community
  • 1
  • 1
Dave Barton
  • 1,429
  • 13
  • 12
  • Could you elaborate a little more? how exactly do I parse a script link into a DOM element and how do I load it into the webview? – daedsidog Nov 28 '15 at 12:23
  • I don't know anything about android, webview, or even java really. I can tell you that your M.parseMath(s) call is a no-op (and a mistake). M.parseMath() should be passed a DOM node, not a string. I don't know where you set functext. It doesn't make sense to set s and then do document.write(s), just put "$$"+functext+"$$" in your js variable (which is really html not js). You only need to call M.parseMath() if you want to create or change mathematics later, after the page is created, e.g. in response to user input. Hope this helps. – Dave Barton Nov 29 '15 at 21:49
  • looks like we share something in common, i too dont know a lot about android, java or webview ;). i tried leaving out M.parsemath and only using document.write(s) and it works fine without it. "functext" is just an equation (ie: 5+54/5). that piece of code gets called every time the user edits the equation, so that it would update and show into the webview.... however the function sometimes gets out of bounds and i need to apply resizing, i currently have a brute method of doing this, but all i want is to figure out when is the perfect moment to do it without displaying artefacts – daedsidog Nov 30 '15 at 17:33