Welcome Guest Search | Active Topics | Sign In | Register

Detect a page loaded to run script in EO.WebBrowser Options
Khoa
Posted: Monday, March 19, 2018 4:17:32 PM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
Hi,

From C# side I can execute JavaScript with webView.EvalScript(script1), then it will go to the 2nd page. However, how can I know this 1st script is finished to run another 2nd script with webView.EvalScript(script2) on 2nd page, then another 3rd script on 3rd page, and so on...

I see the event webView.LoadCompleted but don't know how to make it work when navigating multiple pages with JavaScript.

Thank you.
eo_support
Posted: Monday, March 19, 2018 5:09:55 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Hi,

I am not sure if I understand your question correctly. EvalScript is synchronous. So by the time EvalScript returns, the script has already finished executing.

Thanks!
Khoa
Posted: Monday, March 19, 2018 5:26:28 PM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
Here is the scenario: my script will submit a form and wait for the XHR request to finish to load another form in the same page. How can I know when the next form fully shows up (or the XHR request is done) to have the second script to run.

Thank you.
eo_support
Posted: Monday, March 19, 2018 5:33:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
That wouldn't have anything to do with the script. The script would submit a load request to the loader and returns immediately. In another word, when the loader finishes and when the script finishes are two different things.

In order to detect whether a page is fully loaded, you can use WebView.JSInitCode to inject additional JavaScript code into the WebView to handle the page's window.load event. The page is done loading when your window.load event is called. Inside your window.load handler, you can call back into the C# side. Just make sure when you are back to C# side this way do not call EvalScript again directly --- use some method to delay the call. For example, if you use Windows.Forms, use Control.BeginInvoke to delay the call. You can not call EvalScript from within a JavaScript -> C# callback because that would cause JavaScript engine to be re-entered, which is not allowed.
Khoa
Posted: Monday, March 19, 2018 6:07:21 PM
Rank: Advanced Member
Groups: Member

Joined: 9/3/2014
Posts: 68
That is interesting to have window.load event in WebView.JSInitCode to capture page loaded, then call back to C# side. I will follow your instructions for that. It is also very interesting to delay the call from C# back to JavaScript.

To know when XHR/Ajax requests are finished, I will include jQuery and use $.ajaxComplete(callback) in WebView.JSInitCode also.

Thank you.
eo_support
Posted: Tuesday, March 20, 2018 8:54:37 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,067
Yes. You can do that. However you may want to minimize the amount of code that you inject with JSInitCode in case it causes interfere with other code in the page.


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.