I have an Internet Explorer BHO (in c# .net) and want to identify either when a user initiates a navigation, or when a user-initiated navigation has completed. By user-initiated i mean clicking on a link or similar action. In particular if there are multiple frames in the document being loaded I want to treat them as a single 'navigation', but I can't think of any easy way to do this. I know the BeforeNavigate2 and DocumentComplete events, but can't see any way to differentiate between BeforeNavigate/DocumentComplete firing when a user has clicked on a link and it firing because a frame is loading.
One possible solution I'm thinking is that the BeforeNavigate2 for the top frame always gets fired before that of the inner frames (obviously), and then the DocumentComplete of the child frames get called before the DocumentComplete of the top, which is always called last. So for instance I could increment a counter in BeforeNavigates and decrement it in DocumentComplete, and only when it's 0 is it a user-initiated navigation.
But I'm not sure if I can rely on this or if there's a better way to do it. e.g. What happens if the user presses ESC after one of the frames but not all have finished loading: does the DocumentComplete of the top frame ever get called?
Any suggestions?