Welcome Guest Search | Active Topics | Sign In | Register

WebView JSInitCode Options
Biz
Posted: Monday, May 16, 2016 6:11:00 PM
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.

eo_support
Posted: Monday, May 16, 2016 6:47:59 PM
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!
Biz
Posted: Monday, May 16, 2016 7:23:49 PM
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?
eo_support
Posted: Monday, May 16, 2016 8:20:30 PM
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.
Biz
Posted: Tuesday, May 17, 2016 12:47:07 PM
Rank: Member
Groups: Member

Joined: 8/26/2014
Posts: 20
Thanks. That clarifies it.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.