|
Rank: Member Groups: Member
Joined: 8/26/2014 Posts: 20
|
Is there any exception handling when you set JSInitCode of a WebView object? If the code has incorrect syntax etc. setting the property does not raise any exception.
If there is no exception handling, is it better to call EvalScript to load common JS functions that can be called later?
Here is what we are trying to do:
* Create a bunch of common Javascript functions. * Call these functions to extract values / automate certain tasks.
Please advise on the best way to achieve this.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
You will have to ensure JSInitCode is correct. Any error in JSInitCode is ignored.
You can use EvalScript over JSInitCode but only JSInitCode is guaranteed to run before everything else. When you load a page and then call EvalScript, by the time EvalScript is called, some JavaScript code in the page may have already run.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 8/26/2014 Posts: 20
|
Thanks for the quick response.
If we load the common code using JSInitCode or EvalScript, will that common code be accessible throughout the browsing session (i.e. as long as the WebView object is not closed)? Is there a way to "inject" a JavaScript file into the session?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
No. JavaScript code is always in the current page --- you must reinjected it into every page. JSInitCode does this automatically as long as you use the same WebView instance. EvalScript must be explicitly called after every load.
|
|
Rank: Member Groups: Member
Joined: 8/26/2014 Posts: 20
|
Thanks. That clarifies it.
|
|