Call an event when the current url loads (excluding iframe websites, etc)

Add-in Express™ Support Service
That's what is more important than anything else

Call an event when the current url loads (excluding iframe websites, etc)
 
czetsuya




Posts: 44
Joined: 2011-05-01
Hi,

Is it possible to only call an action when the main page loads? It's because I have a page with frame/iframe inside and I got multiple document load event.

Can we determine if the request came from an iframe?

Thanks,
czetsuya
Posted 25 May, 2011 22:35:43 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Czetsuya,

To detemine the currently loaded url you can use the pDisp parameter of the DocumentComplete event handler.

private void IEModule_DocumentComplete(object pDisp, string url)
{
if (pDisp is IE.IWebBrowser)
{
IE.IWebBrowser browser = pDisp as IE.IWebBrowser;
mshtml.IHTMLDocument2 doc = browser.Document as mshtml.IHTMLDocument2;
}
}
Posted 26 May, 2011 05:01:37 Top
czetsuya




Posts: 44
Joined: 2011-05-01
Hi Sergey,

Thanks for the reply, actually that's how I implement my current code. But a url inside an iframe also gets to that condition so the code inside is called n times. What I want is for the code to be executed once per url on the web browser.

Regards,
czetsuya
Posted 26 May, 2011 07:59:48 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Please try the code below:

private void IEModule_DocumentComplete(object pDisp, string url)
{
if (pDisp is IE.IWebBrowser2)
{
IE.IWebBrowser2 browser = pDisp as IE.IWebBrowser2;

int hwnd = 0;

try
{
hwnd = browser.HWND;
}
catch (Exception)
{
}

if (hwnd != 0)
{
// run custom code
}
}
}
Posted 26 May, 2011 12:31:30 Top