How to detect when a web page is finished loading?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
arslanbhatti
Posts: 1
Joined: 14 Jul 2018, 11:30

How to detect when a web page is finished loading?

14 Jul 2018, 12:00

Hi Seniors!
is there any alternative code for AHK_L to wait for the page load complete request. like sean's code for AHK Basic

Code: Select all

#Persistent
sUrl :=	"http://www.autohotkey.com/forum/"

COM_Init()
pweb :=	COM_CreateObject("InternetExplorer.Application")
sink :=	COM_ConnectObject(pweb, "IE_")
COM_Invoke(pweb, "Visible", True)

bComplete := False
COM_Invoke(pweb, "Navigate2", sUrl)
While !bComplete
      Sleep, 500

COM_DisconnectObject(sink)
COM_Release(pweb)
COM_Term()
Return

OnComplete:
bComplete := True
Return

IE_DocumentComplete(prms, sink)
{
	If	NumGet(NumGet(prms+0)+24) = NumGet(sink+12)
		SetTimer, OnComplete, -10
/* more rigorous way
	COM_Release(punk1:=COM_QueryInterface(NumGet(NumGet(prms+0)+24),0))
	COM_Release(punk2:=COM_QueryInterface(NumGet(sink+12),0))
	If   (punk1 = punk2)
		SetTimer, OnComplete, -10
*/
}

IEReady(hIESvr = 0)
{
	If Not	hIESvr
	{
		Loop,	50
		{
			ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, A ; ahk_class IEFrame
			If	hIESvr
				Break
			Else	Sleep 100
		}
		If Not	hIESvr
			Return	"""Internet Explorer_Server"" Not Found."
	}
	Else
	{
		WinGetClass, sClass, ahk_id %hIESvr%
		If Not	sClass == "Internet Explorer_Server"
			Return	"The specified control is not ""Internet Explorer_Server""."
	}

	COM_Init()
	If	DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
	&&	DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)=0
	&&	pdoc && pweb:=COM_QueryService(pdoc,IID_IWebBrowserApp:="{0002DF05-0000-0000-C000-000000000046}")
	{
		While,	COM_Invoke(pweb, "ReadyState") <> 4
		Sleep,	500
		While,	COM_Invoke(pweb, "document.readyState") <> "complete"
		Sleep,	500
		COM_Release(pweb)
	}
	COM_Release(pdoc)
	COM_Term()
	Return	pweb ? "DONE!" : False
}
User avatar
TheDewd
Posts: 1510
Joined: 19 Dec 2013, 11:16
Location: USA

Re: How to detect when a web page is finished loading?

16 Jul 2018, 14:19

See example code below.

Code: Select all

While (IE.ReadyState <> 4) || (IE.Busy) {
	Sleep, 100
}

Code: Select all

#SingleInstance, Force

IE := ComObjCreate("InternetExplorer.Application")
IE.Visible := false
IE.Navigate("https://autohotkey.com/boards/")

While (IE.ReadyState <> 4) || (IE.Busy) {
	Sleep, 100
}

For Window In ComObjCreate("Shell.Application").Windows {
    If (Window.LocationName = "AutoHotkey Community - Index page") {
		MsgBox, % Window.Document.body.innerHTML
    }
}

IE.Quit

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, mamo691, MrDoge and 241 guests