MarcoM
MarcoM

Reputation: 92

refresh (F5) eventHandler in BHO for IE9

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...
 }

Upvotes: 0

Views: 1787

Answers (2)

afourney
afourney

Reputation: 1665

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:

Upvotes: 3

Favonius
Favonius

Reputation: 13974

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

Upvotes: 1

Related Questions