OnBeforeNavigate2 & DOM ready?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trogster
    New Member
    • Nov 2009
    • 1

    #1

    OnBeforeNavigate2 & DOM ready?

    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 OnBeforeNavigat e2 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:
    Code:
            public int SetSite(object site)
            {
                if (site != null)
                {
                    webBrowser = (WebBrowser)site;
                    webBrowser.BeforeNavigate2+=new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
                }
                else
                {
                    webBrowser.BeforeNavigate2 -= new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);
                    webBrowser = null;
                }
                return 0;
            }
    And in that event:
    Code:
    public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
            {
                    document = (HTMLDocument)webBrowser.Document;
                    string URI;
                    if (URL.ToString().ToLower() == "about:blank")
                    {
                        URI = document.url;
                    }
                    else
                    {
                        URI = URL.ToString();
                    }
                    //How can I find if this is the first request to the main URL?
            }
    An example of what I am trying to achieve would be:

    I open IE, I type google.com, OnBeforeNavigat e2 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 OnBeforeNavigat e2 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.
Working...