Connecting Tech Pros Worldwide Help | Site Map

OnBeforeNavigate2 & DOM ready?

Newbie
 
Join Date: Nov 2009
Posts: 1
#1: 1 Week Ago
Hello, I am working on a BHO for ie and I'm having some problems.
I have two questions.

1) How can I identify the first request for each website visited on IE (because OnBeforeNavigate2 and other events gets triggered more than once per website).

2) I want to get the website metatags in but how can I know when the DOM is ready and it's not the about:blank or a previous website DOM? (I don't want to wait for images and all that, only the html source).

Here's a little explanation of my code.
In the BHO I use:
Expand|Select|Wrap|Line Numbers
  1.         public int SetSite(object site)
  2.         {
  3.             if (site != null)
  4.             {
  5.                 webBrowser = (WebBrowser)site;
  6.                 webBrowser.BeforeNavigate2+=new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
  7.             }
  8.             else
  9.             {
  10.                 webBrowser.BeforeNavigate2 -= new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
  11.                 webBrowser = null;
  12.             }
  13.             return 0;
  14.         }
And in that event:
Expand|Select|Wrap|Line Numbers
  1. public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
  2.         {
  3.                 document = (HTMLDocument)webBrowser.Document;
  4.                 string URI;
  5.                 if (URL.ToString().ToLower() == "about:blank")
  6.                 {
  7.                     URI = document.url;
  8.                 }
  9.                 else
  10.                 {
  11.                     URI = URL.ToString();
  12.                 }
  13.                 //How can I find if this is the first request to the main URL?
  14.         }
An example of what I am trying to achieve would be:

I open IE, I type google.com, OnBeforeNavigate2 gets triggered for the first time and I get the main url in URI and I do whatever I want with it. Now I want to ignore all the OnBeforeNavigate2 until a new website is visited, could be by typing the url, clicking a link, etc.

I hope someone can help me out with this.

Regards.
Reply