Welcome Guest Search | Active Topics | Sign In | Register

EO.WebBrowser Javascript not running with JSInitCode Options
Ioannis
Posted: Friday, June 3, 2016 2:48:39 PM
Rank: Newbie
Groups: Member

Joined: 5/13/2016
Posts: 5
I was beating my head against the wall for the last two days but finally solved my own problem. I thought I would post it here in case anyone else was having the same problem, plus I think I found a good practice whenever using WebView1.JSInitCode = myScript

I had an extensive javascript (about 4k compressed) I was "inserting" with JSInitCode.

The main functions were listeners, and they weren't running on all web sites unless the page was refreshed. After investigating, I found they were "inserted" into the page but just didn't work until a refresh, on some pages (which is was very confusing).

ANYWAY - the solution was that the javascript needed to be inserted into an onload function...!!!!

NOTE: THIS ONLY APPLIES TO LISTENERS....


Quote:

window.onload = function () {

eoWebBrowser.extInvoke('windowLoaded', [String(window.location)]);

// MY FUNCTIONS AND STUFF.....


}


eo_support
Posted: Saturday, June 4, 2016 9:11:16 AM
Rank: Administration
Groups: Administration

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

Thanks for sharing. This makes prefect sense. JSInitCode is called BEFORE everything else when the page loads. So other things takes time to load in your page and the code in JSInitCode relies on it, then most likely the code will fail. Calling it in window.onload would usually avoid this problem thus make it work.

As a way to troubleshoot, you can also handle the WebView.ConsoleMessage event. This event is raised when an JavaScript error occurs.

Thanks!


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.