|
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.
|
|
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!
|
|
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.
|
|
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!
|
|
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.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Yes. That will work. Thank you very much for sharing!
|
|
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.
|
|
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.
|
|
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.aspxYou 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!
|
|