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)
{
if (this.site != null)
{
Marshal.ReleaseComObject(this.site);
}
if (this.explorer != null)
{
Marshal.ReleaseComObject(this.explorer);
this.explorer = null;
}
this.site = pUnkSite as NativeMethods.IInputObjectSite;
if (this.site != null)
{
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
{
object webBrowser;
provider.QueryService(ref guid, ref riid, out webBrowser);
this.explorer = webBrowser as InternetExplorer;
try
{
explorer.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(explorer_DocumentComplete);
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