问题
There is the "execute(String javaScript)" method in the BrowserComponent class. Could you please explain how this work?
When would the JavaScript be executed - after the page and any external .js files are fully loaded?
If I pass a string which is to execute a method in an external .js file, would this work?
Thanks!
回答1:
BrowserComponent.execute(String)
will execute the provide JS snippet in the current page of the browser at the time that you make the call. If your snippet references things that aren't loaded yet, then the javascript will result in an error.
If you want to ensure that the page has finished loading before your snippet is run, then you'll need to provide your own checks. If you execute your js inside the onLoad event of the browser component, then the page will have been loaded. Any <script>
tags in the page should also have loaded by that time (as long as they aren't loaded async).
来源:https://stackoverflow.com/questions/43539689/clarification-on-codename-ones-browsercomponent-executestring-javascript-meth