Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
private void explorer_DocumentComplete(object pdisp, ref object URL)
{
   MessageBox.Show("DocumentComplete");
}


and

C#
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

I have get the problem,too. Did you get the solution?
https://support.microsoft.com/en-us/kb/325079[^]
 
Share this answer
 
Comments
CHill60 23-Oct-15 9:34am    
Did you not see the OP's post from 12-Mar-2012?
I Followed this solution:
http://social.msdn.microsoft.com/Forums/nl-NL/ieextensiondevelopment/thread/20b16462-63bd-4df4-8f2f-900307252ede[^]

I implemented it as follows:

C#
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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900