简体   繁体   English

IE9的BHO中的刷新(F5)eventHandler

[英]refresh (F5) eventHandler in BHO for IE9

which event is rised up in Internet Explorer (IE9) when the F5 key (refresh) is clicked? 单击F5键(刷新)在Internet Explorer(IE9)中引发哪个事件? And how can I catch it with an Handler in my BHO? 我如何在BHO中使用处理程序来捕获它?

Note: I have created a BHO in C# for IE9. 注意:我已经在IE9的C#中创建了BHO。 My class extend IObjectWithSite that allow me to add handlers through SetSite function. 我的课程扩展了IObjectWithSite,使我可以通过SetSite函数添加处理程序。

public int SetSite(object site)
 {
   webBrowser = (SHDocVw.WebBrowser)site; 
   //events here...
 }

If you are developing a browser plugin that injects Javascript, I found it useful to hook both ondocumentcomplete and ondownloadcomplete. 如果您正在开发一个注入Javascript的浏览器插件,我发现钩住ondocumentcomplete和ondownloadcomplete很有用。

  • Ondocumentcomplete fires as soon as the DOM has been loaded and can be manipulated, but it misses refreshes. DOM加载并可以对其进行操作后,就会立即触发Ondocumentcomplete,但它会丢失刷新。

  • Ondownloadcomplete waits until all resources (eg, images) have downloaded, but catches refreshes. Ondownloadcomplete等待直到所有资源(例如图像)都已下载,但是捕获刷新。 This delay can be quite long. 此延迟可能会很长。

By hooking both, you get a responsive plugin most of the time, and you don't miss refreshes. 通过同时钩住这两个选项,您在大多数情况下都会获得响应式插件,并且不会错过任何刷新。 Your javascript can then include a check to avoid running twice. 然后,您的JavaScript可以包含检查,以避免运行两次。 Something like: 就像是:

// Inject the code, but only once
if (typeof myplugin == 'undefined') {
    myplugin = new function () {
        // Your code runs here.
    };
}

I found the following page to be informative: 我发现以下页面可为您提供丰富的信息:

There is no direct method and it is hard to implement across different versions of IE. 没有直接的方法,并且很难在不同版本的IE中实现。 Although you can use combination of some events to achieve that. 尽管您可以结合使用一些事件来实现。 Be warned the following approaches are not fool proof. 警告以下方法并非万无一失。

Links: 链接:

  1. MSDN Forum MSDN论坛
  2. Detecting the IE Refresh button 检测IE刷新按钮
  3. Refresh and DISPID_DOCUMENTCOMPLETE 刷新和DISPID_DOCUMENTCOMPLETE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM