If you're writing a script that relies on a webpage being fully loaded, there's a simple little AppleScript snippet you can use to determine if the page is loaded or not. The code is:
tell application "Safari"
delay 0.5
repeat until ((do JavaScript "document.readyState" in document 1) is "complete")
delay 0.25
end repeat
-- Action to perform once page is loaded.
end tellThe most important part of this script is the 'do javascript "document.readyState" ' section. This will return the current load status of the page.
While I haven't tested this with earlier versions of Safari, I have found that this works with Safari 4 in both Leopard and Snow Leopard.


0 comments:
Post a Comment