Konrad Gorski
Guest
|
Hi,
I want to inject some js's after page is loaded.
I found quite good answer for my problem here 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:
some product on Amazon
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);
}
}
} |
|
Konrad Gorski
Guest
|
I just found that it's not url-dependant effect.
Same problem is on www.google.pl, for example.
Regards
Konrad |
|
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). |
|
Konrad Gorski
Guest
|
Hi Eugene,
I found "temporary" solution here 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 |
|
Eugene Astafiev
Guest
|
Good news, Konrad!
Thank you for letting us know and good luck with your add-in project. |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
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. |
|