How can I detect if the user selected Refresh
via the context menu? The NavigateComplete2
method does not get invoked when the user selects it.
More importantly, to set own custom user agent, one way to do it is to hook the BeforeNavigate2
event method and it is necessary to know if the user has selected Refresh or navigating a new url.
Any insight would be appreciated.
This demonstrates the NavigateComplete2
method does not get fired when Refresh
is selected.
oWB := new WebBrowserControl("http://stackoverflow.com")
Class WebBrowserControl
{
__New(strURL) {
static WB
Gui, New, Resize
Gui, Add, ActiveX, vWB w780 h580, Shell.Explorer
Gui, show, w800 h600
ComObjConnect(WB, this)
WB.Navigate(strURL)
Loop
Sleep 10
Until (WB.readyState=4 && WB.document.readyState="complete" && !WB.busy)
Return
GuiClose:
ExitApp
}
NavigateComplete2(oParams*) {
ComObjError(false)
WB := oParams[1]
msgbox, 64, Navigate Completed
, % "WB.locationURL :`t`t" WB.locationURL "`n"
. "WB.Document.URL:`t`t" WB.Document.URL "`n"
. "windowlocation.href:`t" WB.document.parentWindow.location.href
}
BeforeNavigate2(oParams*) {
WB := oParams[8]
strURL := oParams[2]
msgbox % "Loading URL:`t`t" strURL "`n"
. "WB.locationURL :`t`t" WB.locationURL "`n"
. "WB.Document.URL:`t`t" WB.Document.URL "`n"
. "location.href:`t`t" WB.document.parentWindow.location.href "`n"
. "WB.ReadyState:`t`t" WB.readystate "`n"
. "WB.document.readystate:`t" WB.document.readystate "`n"
. "WB.Busy:`t`t`t" WB.Busy "`n"
}
}
One way to see if a refresh (or new page) has been initiated is to monitor the mouse state (in Chrome, not sure about other browsers) with: if/while (A_Cursor = "AppStarting"). This is true when the mouse cursor has turned into an hourglass.
Comparing the previous and the new URL would tell you if this is a new request or a refresh: ControlGetText CurrentURL, Chrome_OmniboxView1, Chrome
Hope this helps.