Click here to Skip to main content
12,074,808 members (57,473 online)
Rate this:
 
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 4:02am
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  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I have get the problem,too. Did you get the solution?
https://support.microsoft.com/en-us/kb/325079[^]
  Permalink  
Comments
CHill60 23-Oct-15 9:34am
   
Did you not see the OP's post from 12-Mar-2012?

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web04 | 2.8.160208.1 | Last Updated 22 Oct 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100