Rank: Advanced Member Groups: Member
Joined: 1/2/2017 Posts: 32
|
Please help.
I need to have JavaScript in one EO.WebBrowser control, invoke JavaScript in another EO.WebBrowser control. For ease of reading, let's call the 1st JavaScript/EO.WebBrowser WB-Call-From and the other WB-Call-To
With the built in Window Web Browser control, this was possible by having the JavaScript in WB-Call-From "know" the "Handle" of the WB-Call-To's web browser control, and then invoke a JavaScript-to-C# call, passing in the "Handle" of the WB-Call-To. Then in the C# code, use the "Handle" with Form.FromHandle, to get the "System.Windows.Form.Control" for WB-Call-To, and WHA-LAH, then "typecast" the "System.Windows.Form.Control" to a Window's Web Browser control, and then have C#-To-JavaScript functionality, invoke the JavaScript in WB-Call-To.
Sadly, the approach with Window's Web Browser control will not work with EO.WebBrowser, as the "Form.FormController" only returns a "System.Windows.Form.Control", and EO.WebBrowser.WebView, is not based off "System.Windows.Form.Control".
The extra trick for this problem is that the WB-Call-From will not be a child/relative of the WB-Call-To. No amount of parent/child/sibling traversing will help find the WB-Call-To. And thw WB-Call-From will only have a "string" in its JavaScript to call. Which was not an issue for a "Handle" (IntPtr), as one could simply convert a IntPtr to an "int" in C#, then use "ToString" to pass to the JavaScript. Bottom line, the WB-Call-From will only have a string to use to identify the WB-Call-To.
What I would like NOT to have to do, is maintain a list/dictionary in my C# code that is global to all EO.WebBrowser controls, that takes the aforementioned string WB-Call-From gets, to then find the WB-Call-To. I say this, as it would require me to manage the global for each EO.WebBrowser control I create, run, destory, etc. But, if this is the only way, then just please let me know.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,258
|
Hi, You will not be able to pass "handle" with EO.WebBrowser like you did with the built-in Web Browser control. You will have to use one of the methods we provided: https://www.essentialobjects.com/doc/webbrowser/advanced/jsext.aspxYou can use either of the methods listed on that page to call from JavaScript into your C# code from your Web-Call-From code. Inside your C# code you can use WebView.EvalScript to call into your Web-Call-To. Thanks!
|
Rank: Advanced Member Groups: Member
Joined: 1/2/2017 Posts: 32
|
Thanks again for the support. Sadly your answer is not going to work, but it is OK, I solved this issue another way.
Whenever I create a EO.WebBrowser control, I put the "Handle" onto a global thread-safe cache, to refer to the EO.WebBrowser control.
This included the WB-Call-From and WB-Call-To EO.WebBrowser control.
Then I continued passing the "Handle" to the JavaScript, as a string to the WB-Call-From. Then when JavaScript in the WB-Call-From invoked C# code, it passed the "Handle as a string" to the C# code, which then searched the thread-safe global cache, to find the actual EO.WebBrowser control for WB-Call-To, and from that I could execute the JavaScript from C# code in the WB-Call-To.
I didn't want to do this, as now I have to maintain the global cache, but that was not so difficult.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,258
|
Great. Glad that you worked it out!
|