从 BHO 监听 HTML 事件

发布于 2024-08-05 00:39:38 字数 955 浏览 5 评论 0原文

我一直在开发一个用 C# 编写的 BHO/工具栏,用于侦听浏览器当前网页上引发的 HTML 事件。该解决方案包括一个名为 HtmlPageEventManager 的可重用类,其用途是为每个打开的新网页订阅给定的 HTML 事件列表。目标是在用户开始与页面元素交互时立即附加处理程序,甚至在页面加载完成之前。使用此类很简单——只需调用构造函数:

var evts = new List() {
    HtmlEvent.onclick, HtmlEvent.ondblclick, HtmlEvent.onkeydown,
    HtmlEvent.onselectstart, HtmlEvent.onselectionchange,
    HtmlEvent.onfocus, HtmlEvent.onselect
};
new HtmlPageEventManager( this, evts, this.HtmlEventHandler );

在此处下载我的解决方案来尝试并向我发送反馈。如果您发现它有用,请随意在您自己的项目中使用它。尽管它运行良好,但有时无法附加事件。我很难确定这些情况。所以我可以使用一些帮助来改进 HtmlPageEventManager。

我的解决方案引用了 SpicIE 的程序集,但它们未包含在上述下载中,因此您需要从 SpicIE 网站 获取它。顺便说一句,这可能是一个好时机来问:SpicIE 有多受欢迎?有什么更好的工具可以使用吗?

I've been working on a BHO/toolbar written in C# that listens to HTML events raised on the browser's current webpage. The solution includes a reusable class called HtmlPageEventManager whose purpose is to subscribe to a given list of HTML events for each new webpage that's opened. A goal is to attach handlers as soon as the user can begin interacting with page elements, even before the page load is complete. Using this class is simple -- just call the constructor:

var evts = new List() {
    HtmlEvent.onclick, HtmlEvent.ondblclick, HtmlEvent.onkeydown,
    HtmlEvent.onselectstart, HtmlEvent.onselectionchange,
    HtmlEvent.onfocus, HtmlEvent.onselect
};
new HtmlPageEventManager( this, evts, this.HtmlEventHandler );

Please download my solution here to try it out and send me feedback. Feel free to use it in your own projects if you find it useful. Although it works well, there are occasions when it fails to attach the events. I've had difficulty pinpointing those circumstances. So I could use some help improving upon HtmlPageEventManager.

My solution references SpicIE's assemblies but they're not included in the above download, so you will need to get it from the SpicIE website . Btw, this is probably a good time to ask: how popular is SpicIE? Any better tool to use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盗心人 2024-08-12 00:39:38

是的!我通过订阅 BHO 的 DownloadComplete 事件克服了“刷新”问题,在该事件中我再次调用附加 HTML 事件处理程序的“RegisterEventHandlers”帮助器方法。链接到的代码 jeffamaphone 很有帮助。我合并了“normalPageLoad”成员变量的想法来有条件地调用 RegisterEventHandlers。我还查看了 随附的论坛帖子。不过,我无法理解对父窗口的 Loaded 事件的强调。我什至没有做那部分就让我的代码工作了。不管怎样,我认为 HtmlPageEventManager 现在功能齐全——敲木头。如果您发现它仍未完成其工作的情况,请给我留言。

Yeah! I overcame the "Refresh" issue by subscribing to the BHO's DownloadComplete event, where I again call my "RegisterEventHandlers" helper method that attaches the HTML event handlers. The code jeffamaphone linked to was helpful. I incorporated its idea of a "normalPageLoad" member variable to conditionally call RegisterEventHandlers. I also looked at the accompanying forum post. I can't understand the emphasis on the parent window's Loaded event, though. I got my code working without even doing that part. Anyway, I think HtmlPageEventManager is fully functional now -- knock on wood. Please give me a shout if you find a case in which it's still not doing its job.

咽泪装欢 2024-08-12 00:39:38

您会发现没有 100% 的解决方案可以在页面加载期间为 IE 执行此操作。这不是你的错:IE 的事件模型是一大堆像意大利面条一样的异步代码,这使得它很难正确执行。如果你得到了 95% 的解决方案,我会说高兴并继续前进。

You're going to find there is no 100% solution to do this for IE during page load. It's not your fault: IE's event model is a giant spaghetti mass of asynchronous code which makes it very difficult to get right. If you've got a solution that is 95%, I say be happy and move on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文