سؤال

which event is rised up in Internet Explorer (IE9) when the F5 key (refresh) is clicked? And how can I catch it with an Handler in my BHO?

Note: I have created a BHO in C# for IE9. My class extend IObjectWithSite that allow me to add handlers through SetSite function.

public int SetSite(object site)
 {
   webBrowser = (SHDocVw.WebBrowser)site; 
   //events here...
 }
هل كانت مفيدة؟

المحلول

There is no direct method and it is hard to implement across different versions of 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
  2. Detecting the IE Refresh button
  3. Refresh and DISPID_DOCUMENTCOMPLETE

نصائح أخرى

If you are developing a browser plugin that injects Javascript, I found it useful to hook both ondocumentcomplete and ondownloadcomplete.

  • Ondocumentcomplete fires as soon as the DOM has been loaded and can be manipulated, but it misses refreshes.

  • Ondownloadcomplete waits until all resources (e.g., images) have downloaded, but catches refreshes. 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. 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:

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top