Miguel Paraz wrote:
> On May 26, 9:47 pm, "Maps.Huge.Info (Maps API Guru)"
> <[email protected]> wrote:
>> This is more a JavaScript question than an Android one.
>>
>> It sounds to me like you could either inline the JavaScript ahead of
>> the page, which would make it execute first, or add an "onload"
>> function so that it executes right after the rest of the page is
>> resolved. Either way should work, if I understand your question.
>>
>> For further reading, I suggest searching Google for basic JavaScript
>> tutorials, there's lots of stuff out there.
>
> Thanks for the reply, John. Sorry I wasn't clear.
>
> I would like WebView to pre-execute the JavaScript without modifying
> the HTML page.
>
> Something like:
>
> webView.loadUrl("javascript:var%20x=1");
> webView.loadUrl("file:///android_asset/page.html"); // page.html will
> then have x available
>
> Except that javascript: URLs do not work properly with spaces in them:
>
> 05-26 22:13:55.412 E/Web Console( 286): SyntaxError: Parse error at
> undefined:1
Rather than pushing, you could try pulling:
webView.addJavascriptInterface("paraz", new TheMiguelParazObject());
webView.loadUrl("file:///android_asset/page.html");
TheMiguelParazObject has some method (e.g., initScript()) that returns
your desired Javascript ("var x=1;");
Your file has a <script> element up front that calls eval() on the
result of paraz.initScript().
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
_The Busy Coder's Guide to Android Development_ Version 3.0
Available!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en