|
Rank: Member Groups: Member
Joined: 6/25/2022 Posts: 10
|
I am migrating from System.Windows.Forms.WebBrowser to EO.Webbrowser. My current code uses IHTMLElement2 objects to attach / detach events to / from DOM Elements of the html document which are implemented in c#. This allows me to call an EventHandler in c# when a event (e.g. "onclick") is fired by a html object in DOM. See also StackOverflowIs there a sample which shows how to implement? Thanks Alex
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi, You would use eoapi.extInvoke or window.external to call back to the C# side. See here for more details: https://www.essentialobjects.com/doc/webbrowser/advanced/jsext.htmlThe code would be something like this:
Code: C#
webView.EvalScript(@"
document.getElementById('button1').onclick = function()
{{
eoapi.extInvoke('command_name', [command_args]);
}}");
This would attach a JavaScript handler to button1's onclick and calls eoapi.extInvoke when the button is clicked. This would in turn trigger the WebView's JSExtInvoke event on the C# side. You can then do whatever you want to do there. Hope this helps. Please feel free to let us know if you still have any more questions. Thanks!
|
|
Rank: Member Groups: Member
Joined: 6/25/2022 Posts: 10
|
Thanks for this tip! But it is still not working as expected. Is WebView.LoadCompleted fired when the DOCUMENT is loaded completed as well or is this (occurs when the page has loaded completely) before this?
I tried this _browser.WebView.EvalScript( @"document.getElementById('inlayImage').onclick=function(){{eoapi.extInvoke('LazyLoadImage');}}");
but my c# Method LazyLoadImage is not called.
Thanks Alex
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
Hi,
eoapi.extInvoke does NOT call your function directly. It rasies the WebView's JSExtInvoke event. As such you would need to handle the WebView's JSExtInvoke event, then call whatever function you want to call inside your event handling code.
You can take a look of our TabbedBrowser sample application source code to see how this event is handled.
WebView.LoadCompleted is fired when the document is loaded. It is very much the C# side equvailent of document.onload event on the JavaScript side.
Hope this helps.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 6/25/2022 Posts: 10
|
This is fine now, thanks a lot. But now there is a problem using InvokeFunction("setInlayImageSrc", s): this is trowing the exception Invoking function 'setInlayImageSrc' failed because the function to be called is invalid. thanks, Alex
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,217
|
pixafe wrote:This is fine now, thanks a lot. But now there is a problem using InvokeFunction("setInlayImageSrc", s): this is trowing the exception Invoking function 'setInlayImageSrc' failed because the function to be called is invalid. thanks, Alex Please only follow up your question in one thread. We will continue discussion on the other thread. Thanks!
|
|