Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.6: An AppleScript to check complete page loading in Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: An AppleScript to check complete page loading in Safari
Authored by: Stef@nK on Nov 10, '09 09:53:50AM
This this a different approach which works also in Tiger (Safari 3 and higher required) and Leopard and avoids GUI scripting

tell application "Safari" to open location "http://www.macosxhints.com/article.php?story=20091101035318405"
if page_loaded(20) then
	say "loaded"
else
	say "failed"
end if

on page_loaded(timeout_value) -- in seconds
	delay 1
	repeat with i from 1 to timeout_value
		tell application "Safari"
			if name of current tab of window 1 is not "Loading" then exit repeat
		end tell
		delay 1
	end repeat
	if i is timeout_value then return false
	tell application "Safari"
		repeat until (do JavaScript "document.readyState" in document 1) is "complete"
			delay 0.5
		end repeat
	end tell
	return true
end page_loaded


[ Reply to This | # ]