سؤال

I am writing a BHO (Browser Helper Object) in IE and I need to track redirection.

Initially I thought BeforeNavigate2 event would be the one I need but I learned that it is actually for frames mainly. Next I found that NavigateComplete2 event of WebBrowserEvents2 seems to be fired up twice when there is a redirection. But I don't know whether my observation is correct and also I don't know how to tell whether a sequence of NavigateComplete2 events are due to redirections or user's clicking. Please advise!

هل كانت مفيدة؟

المحلول

I found in lots of trial and error that if you compare Browser interface pointer passed from BeforeNavigate2 with the one you get when you created BHO, you can figure out what the real beginning url is. When they are the same, the url passed to BeforeNavigate2 is the one you need. You need to compare it against the one you get from NavigateComplete2. If they are different, then it is a sign of redirection. One gotcha is when a new window is opened. In that case you need to keep an eye on NewWindow event as well and do some special processing (when a new window is opened, BeforeNavigate2 URL will be passed to NavigateComplete2 as well so you need to set a flag and handle accordingly).

نصائح أخرى

In a situation similar to yours where NavigateComplete2 was being fired off by separate frames within a browser object, I found that DocumentComplete did the trick, waiting for ALL frames to be loaded before triggering. Perhaps this could help in your situation?

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