浏览器控件 onclick 事件 [英] Webbrowser control onclick event

查看:50
本文介绍了浏览器控件 onclick 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码可以点击一个 html 元素,但它不会触发它的 java 脚本代码,在 VBA 中,我曾经调用initEvent"来调用 java 脚本事件.我在网上搜索过,没有找到合适的解决方案.

I have a code that clicks an html element but it doesn't fire its java script code, in VBA I used to call "initEvent" in order to invoke a java script event. I have searched the web and haven't found a suitable solution.

有一个可行的解决方案,但在大多数情况下它不是很有用,在 url 中放置一个 java 脚本代码并导航到它,但是有时需要 html 元素的位置,这有时是一个问题.

There's a working solution, but it's not quite useful in most cases, placing a java script code in the url and navigating to it, however there's a need for the location of the html element which is a problem sometimes.

我用来点击 html 元素的代码:

The code I use in order to do a click in the html element :

el.InvokeMember("onclick");

也试过:

el.InvokeMember("click");

我放在 url 中的代码并没有太大用处:

The code that I place in the url and find not too much useful :

wb.Navigate("javascript: document.getElementsByClassName('something')[0].click();void(0);");

我希望得到一个可行的解决方案,提前致谢.

I hope to receive a working solution, thanks in advance.

推荐答案

我已经解决了,我想说的是一个非常原始的解决方案.所以基本上,我是这样考虑的.找到一个我已经拥有的元素根本不舒服,所以java脚本导航似乎没有用,但是,我想改变它以适应任何元素,问题是如何.

I've solved it, a very original solve I'd say. So basically, I've thought about it this way. Finding an element that I already have is not comfortable at all, so the java script navigate didn't seem useful, however, I thought of changing it to fit any element, the question was how.

我想出的答案是,如果我将焦点放在特定元素上,然后使用 javascript 单击焦点元素,结果会怎样.

The answer I came up with, what if I'd focus the specific element and then use a javascript to click on the focused element, and it worked.

所以固定代码:

el.Focus();
wb.Navigate("javascript: document.activeElement.click();void(0);");

我希望它对你们中的一些人有用.

I hope it'll be useful to some of you.

这篇关于浏览器控件 onclick 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆