Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Explorer
Hi all, I'm coding an extension for Internet Explorer.
I'de like to catch the IE beforenavigate event.
I do this in my code in this way:
 
After implementing IObjectWithSite interface, I define SetSite method as follow:
 
public void SetSite(object pUnkSite)
{
            
  // Release previous COM objects.
  if (this.site != null)
  {
     Marshal.ReleaseComObject(this.site);
  }
  if (this.explorer != null)
  {
     Marshal.ReleaseComObject(this.explorer);
     this.explorer = null;
  }
  // pUnkSite is a pointer to object that implements IOleWindowSite. 
  this.site = pUnkSite as NativeMethods.IInputObjectSite;
  if (this.site != null)
  {
     // The site implements IServiceProvider interface and can be used to 
     // get InternetExplorer instance.
     var provider = this.site as NativeMethods._IServiceProvider;
     Guid guid = new Guid("{0002DF05-0000-0000-C000-000000000046}");
     Guid riid = new Guid("{00000000-0000-0000-C000-000000000046}");
     try
     {
        //allochiamo il nostro browser e diciamo che è IE
        object webBrowser;
        provider.QueryService(ref guid, ref riid, out webBrowser);
        this.explorer = webBrowser as InternetExplorer;
        try
        {
                        
           //let's attach document complete
           explorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(explorer_DocumentComplete);
           //let's attach beforeNavigate
           explorer.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(explorer_BeforeNavigate2);
        }
        catch (Exception ex)
        {
           listBox2.Items.Add(ex.Message);
        }
     }
     catch (COMException)
     {
     }
  }
}
 
And then I Implment my two attached events as follow:
 
private void explorer_DocumentComplete(object pdisp, ref object URL)
{
   MessageBox.Show("DocumentComplete");
}
 
and
 
private void explorer_BeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)
{
   MessageBox.Show("BeforeNavigate");
}
 
What happens is that DocumentComplete event works and BeforeNavigate2 does not.
 
Where is my fault?
 
CAn anyone help me with this issue?
 
Thank you very much in advance,
 
Pietro
Posted 9-Mar-12 3:02am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I Followed this solution:
http://social.msdn.microsoft.com/Forums/nl-NL/ieextensiondevelopment/thread/20b16462-63bd-4df4-8f2f-900307252ede[^]
 
I implemented it as follows:
 
        public void SetSite(object pUnkSite)
        {
            
            // Release previous COM objects.
            if (this.site != null)
            {
                Marshal.ReleaseComObject(this.site);
            }
            if (this.explorer != null)
            {
                Marshal.ReleaseComObject(this.explorer);
                this.explorer = null;
            }
            // pUnkSite is a pointer to object that implements IOleWindowSite. 
            this.site = pUnkSite as NativeMethods.IInputObjectSite;
            if (this.site != null)
            {
                // The site implements IServiceProvider interface and can be used to 
                // get InternetExplorer instance.
                var provider = this.site as NativeMethods._IServiceProvider;
                Guid guid = new Guid("{0002DF05-0000-0000-C000-000000000046}");
                Guid riid = new Guid("{00000000-0000-0000-C000-000000000046}");
                try
                {
                    //allochiamo il nostro browser e diciamo che è IE
                    object webBrowser;
                    provider.QueryService(ref guid, ref riid, out webBrowser);
                    this.explorer = webBrowser as InternetExplorer;
 
                    //agganciamo document complete
                    explorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(explorer_DocumentComplete);
 
                    //agganciamo beforeNavigate
                    axDocumentV1 = (WebBrowser_V1)this.explorer;
                    axDocumentV1.BeforeNavigate += axDocumentV1_BeforeNavigate;
 
                }
                catch (COMException)
                {
                }
            }
        }
 
I declared inside my class:
 
        private SHDocVw.WebBrowser_V1 axDocumentV1;
 
Pietro
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 910
1 OriginalGriff 508
2 thatraja 225
3 Abhinav S 218
4 Emre Ataseven 200
0 Sergey Alexandrovich Kryukov 8,142
1 OriginalGriff 4,665
2 Peter Leow 3,774
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 12 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid