Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

HOWTO - Call JavaScript function from C# - WebView.EvalScript. Options
JSB
Posted: Wednesday, October 11, 2017 1:49:19 PM
Rank: Advanced Member
Groups: Member

Joined: 1/2/2017
Posts: 32
Please help.

I'm getting an error when trying to call a JavaScript function from WebView.EvalScript.
The error thrown by WebView.EvalScript is as such:

- , line 1, col 0 - 1: Uncaught ReferenceError: MyFunc is not defined

First off, I know "MyFunc" is valid and works with no errors. This is easily proven by simply having the JavaScript call "MyFunc" when the page's [ $(document).ready ] gets invoked (jQuery of course). So, when I got this error, I then tired "alert" instead of "MyFunc" and it worked. With that known, I went back to the documentation on EvalScript, and read between the lines, but could not find any reason why "alert" should work, vs "MyFunc" which does work.

Something must be missing. I even though of trying inside the [ $(document).ready ] to set "window.MyFunc = function() { ~~~ }", but that failed as well on such code as such:

JSFunction MyFunc_1 = (JSFunction)WebView1.EvalScript("Myfunc"); // Returns null. LastJSException set to the error above.
JSFunction MyFunc_2 = (JSFunction)WebView1.EvalScript("window.Myfunc"); // Returns null. LastJSException set to the error above.

What am I missing?
JSB
Posted: Wednesday, October 11, 2017 4:54:46 PM
Rank: Advanced Member
Groups: Member

Joined: 1/2/2017
Posts: 32
I have an update on this issue. The logic for EvalScript works fine. My issue was a BUG else where, that used the wrong EO.WebBrowser/WebView object.

For anyone else falling into this trap, all I can say is that because the EO.WebBrowser works in WinForms via Controls.Add, where you use a dummy control, one can use the "Handle" off the dummy control to trace things, if you share the "Handle" into the HTML rendered in the EO.WebBrowser control. This is how I found out that I was using EvalScript on a different EO.WebBrowser/WebView control.
eo_support
Posted: Wednesday, October 11, 2017 5:20:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 19,668
Great. Thanks for the update!


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.