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

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) (repeated)
 
Konrad Gorski


Guest


Hi,
I want to inject some js's after page is loaded.
I found quite good answer for my problem http://www.add-in-express.com/forum/read.php?FID=10&TID=9416&MID=48301 but on some url's event DocumentComplete is fired once (mostly, ok), two times (very strange, happens few times) or sometimes never! Especially by page reloads event don't fire every so often (using F5, 1-3 times for 10 reloads).
I'm stuck: can understand 'never fired' or 'always fired' but sometimes?
Example url:
http://www.amazon.com/Canon-T3i-Processor-3-0-Inch-Vari-Angle/dp/B004J3V90Y/ref=sr_1_4?s=photo&ie=UTF8&qid=1347461964&sr=1-4

What is a proper way to determine when top document is loaded?

Regards
Konrad
ps. used browser IE9, code:
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
MessageBox.Show("IEModule_DocumentComplete: " + url);

}
}
}
Posted 12 Sep, 2012 15:08:36 Top
Konrad Gorski


Guest


I just found that it's not url-dependant effect.
Same problem is on www.google.pl, for example.

Regards
Konrad
Posted 12 Sep, 2012 15:28:29 Top
Eugene Astafiev


Guest


Hi Konrad,

The following code works like a charm on my PC with Internet Explorer 9 installed:

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
           System.Diagnostics.Debug.WriteLine("IEModule_DocumentComplete: " + url); 
       }
   }
}


Please try to replace the MessageBox.Show method with the System.Diagnostics.Debug.WriteLine statement. Do you get "the custom code" running now?

BTW Sometimes it is fired twice. It looks like this depends on the web page. However, I always get the custom code running on my PC (even with your URL).
Posted 13 Sep, 2012 10:46:26 Top
Konrad Gorski


Guest


Hi Eugene,

I found "temporary" solution http://www.add-in-express.com/forum/read.php?FID=10&TID=10093 and it's stable: event DownloadComplete and check IeApp.ReadyState for READYSTATE_COMPLETE.

Your code still don't work for me. As I see, problem is on my side only so I'll check it on others PC's with IE9.

Thanks for fast replay.

Regards
Konrad
Posted 13 Sep, 2012 13:29:12 Top
Eugene Astafiev


Guest


Good news, Konrad!

Thank you for letting us know and good luck with your add-in project.
Posted 14 Sep, 2012 03:35:21 Top
Sergey Grischenko


Add-in Express team


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

The latest version provides the DocumentComplete2 event. The event contains the 'rootDocLoaded' parameter.
It is set to true if the root document is completely loaded. Also, to determine if the user refreshes the web page, you can use the OnBeforeRefresh event handler.
Posted 14 Sep, 2012 05:47:23 Top