Wednesday, May 11, 2011

How to check the clicking of "Refresh button" in a Browser Help Object with C#

How to check the clicking of "Refresh button"

It is not a good experience.

In the versions of 0.9.2.x, the event handler was set many times at each "DownloadComplete". But in fact once is enough, too many times will reduce the loading speed indeed.

The reason is that we cannot catch the clicking of "Refresh button", I have no idea that why Microsoft never leave this interface, it is very bad.

Unexpectedly, I found this code is helpful:

//in NavigateComplete2 or other place:
document
= ieInstance.Document as IHTMLDocument3;
rootElementEvents
= document.documentElement as HTMLElementEvents2_Event;

Then when the refresh button is clicked:

//place this code in DownloadBegin
if (rootElementEvents != document.documentElement as HTMLElementEvents2_Event)
{
MessageBox.Show("You might click the refresh button just now");
}

The new tab and event handler

A new tab opened by clicking the URL (or clicking a URL with middle button, or right button then select "open in new tab"), cannot be set event handler in 'NavigateComplete2', but "DownloadComplete" is OK.

It is not right in "NotGood".

Conclusions

We can drop re-navigating, cut down the times of handler setting.


No comments: