Welcome Guest Search | Active Topics | Sign In | Register

WebControl/WebView - Event for selected control Options
CQuest
Posted: Thursday, September 15, 2016 6:49:49 AM
Rank: Newbie
Groups: Member

Joined: 9/15/2016
Posts: 4
Hi,

Having previously used the IE dll to provide an embedded browser, I was able to subscribe to a click event for the browser. When I clicked on each control this event would fire and the outerHTML would give me the INPUT command for that control.

Code: C#
private Boolean webBrowser_OnCLick(IHTMLEventObj e)
{	
	String html = e.srcElement.outerHTML;
}


Is there a way to achieve the same result in EO.WebBrowser/Webview.

I need to identify INPUT controls so that I can display a touchscreen keyboard.

Thanks,

Chris.
eo_support
Posted: Thursday, September 15, 2016 9:03:16 AM
Rank: Administration
Groups: Administration

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

No. There is no direct replacement for that. You can handle the WebView's MouseClick event, but that event does not give you which element has been clicked. What you can do is:

1. Inject JavaScript code into the page with WebView.JSInitCode to hook up body element's click event;
2. Inside your JavaScript code click event handler collects information about which element has been clicked;
3. Handle the WebView's MouseClick event, inside this event handler uses WebView.EvalScript to fetch information you collected in step 2;

As for touch keyboard, EO.WebBrowser supposes to automatically display the touch keyboard for you. Have you tried it yet?

Thanks!

CQuest
Posted: Thursday, September 15, 2016 9:10:55 AM
Rank: Newbie
Groups: Member

Joined: 9/15/2016
Posts: 4
Hi,

I don't think that our corporate customer would be very happy having code injected into their web pages.

Unfortunately, I am not using a version of Windows that is touch aware (POSReady 2009 which is essentially Windows XP) so it doesn't have that capability.

I guess I will have to look at other .Net Chrome controls.

Thanks.
eo_support
Posted: Thursday, September 15, 2016 9:20:22 AM
Rank: Administration
Groups: Administration

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

The script is injected by your code, not by the customer --- the same way as the browser engine itself injects a lot of other JavaScript code into the page whenever needed. For example, Chrome's DevTools injects script into the target page in order to debug the page. There is nothing new or special about this and it has nothing to do with the page author/end user. It's just an implementation details that they should not care about or even need to be aware of.

Thanks!
CQuest
Posted: Friday, September 16, 2016 4:56:51 AM
Rank: Newbie
Groups: Member

Joined: 9/15/2016
Posts: 4
Hi,

Thanks for this. While investigating step 3, I found this in the forum

Code: C#
//Get the current element
JSObject activeElement = (JSObject)webView.EvalScript("document.activeElement");

//Get the name attribute
string name = (string)activeElement["name"];


I just changed name to outerHTML and it gave me the HTML for the INPUT element that I needed so making steps 1 and 2 unecessary.
eo_support
Posted: Friday, September 16, 2016 7:33:26 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Yes. That will work. Thank you very much for sharing!
CQuest
Posted: Friday, September 16, 2016 9:14:32 AM
Rank: Newbie
Groups: Member

Joined: 9/15/2016
Posts: 4
No problem.

One other thing I noticed that (perhaps) wasn't obvious. To inject the javascript using JSInitCode, this needed to be set before setting the URL on the webview. Probably obvious after the fact.

I used,

Code: C#
webView1.JSInitCode = "windows.onclick =function(){alert('Clicked on page!');}"


to test that the injection was working.
nomdeplume
Posted: Wednesday, January 11, 2017 2:08:22 PM
Rank: Newbie
Groups: Member

Joined: 10/15/2014
Posts: 8
eo_support wrote:
Hi,

No. There is no direct replacement for that. You can handle the WebView's MouseClick event, but that event does not give you which element has been clicked. What you can do is:

1. Inject JavaScript code into the page with WebView.JSInitCode to hook up body element's click event;
2. Inside your JavaScript code click event handler collects information about which element has been clicked;
3. Handle the WebView's MouseClick event, inside this event handler uses WebView.EvalScript to fetch information you collected in step 2;

As for touch keyboard, EO.WebBrowser supposes to automatically display the touch keyboard for you. Have you tried it yet?

Thanks!



Any examples of how 2 and 3 actually interact? I've scoured every page that returns hits on JSInitCode and Evalscript....and it's a bit obtuse on their use. I've got the JSInitCode putting up an alert box of and element when being clicked...I'd like to pass that information back into .net to make use of it but don't see how.
eo_support
Posted: Wednesday, January 11, 2017 2:18:36 PM
Rank: Administration
Groups: Administration

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

In order for you to pass information back from JavaScript to .NET code, you would call eoapi.exeInvoke and then handle the WebView's JSExtInvoke event on the .NET side. Whatever arguments that you call extInvoke from JavaScript will be passed to your .NET side JSExtInvoke event's event argument. See here for more details:

https://www.essentialobjects.com/doc/webbrowser/advanced/jsext.aspx

You can also return value from .NET side to the JavaScript side by setting e.ReturnValue from your JSExtInvoke handler.

Hope this helps. Please feel fee to let us know if you still have any questions.

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.