Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Safari Page Loaded

I've read others here and have tried the
"do JavaScript "document.readyState" in document 1" loop.

The problem is I get a complete return before the page is done. I seem to get it when the connection is made not when the page is completely loaded,

I'm not up on Java or html but I think it uses a "Active Server Page". It has .aspx? followed by a long line of key numbers.

Is there a way or different term other than "complete' for the line of java that will make it wait until the page is done. Delay in the script just won't work as the page may take a couple to many seconds to load.

Any help is greatly appreciated.

Marshall

G5 Quad, Mac OS X (10.4.4)

Posted on Jan 24, 2006 12:24 PM

Reply
8 replies

Jan 25, 2006 5:52 AM in response to macBidder

I use this arrangement:

in the main script - to pause until the page is loaded:

If my page_loaded(50) ...

and then the subroutine:

on page loaded(timeoutvalue)
delay 5
tell application "Safari"
repeat with i from 1 to the timeout_value
If (do Javascript "document.readyState"in document 1) is "complete" then return true
delay 1
end repeat
end tell
return false
end page_loaded

This works most of the time, but I have observed problems when my PowerBook is overloaded - or there's heavy network activity - when it seems that the document readystate tests true halfway thru the actual page load. This is for no apparent reason other than these loads and almost seems as though Safari might be 'giving up' and changing the readystate precipitately! You could try testing for "loaded" as well to see if that helps.

Jan 25, 2006 7:56 AM in response to Arkouda

Replying to you earlier set me thinking about this again, and I think I have the answer:

If you check for "complete" before the remote site has started to send data, it will test TRUE. So what I did was to use the JavaScript "document.title" as another condition. (Incidentally, if Safari shows "Untitled" in the Window, this tests as a null string "") As soon as the remote site starts to send, the loaded state will change from "complete" and the window title will have contents.

(In pseudocode: IF your window title is NOT "" AND your loaded state is "complete" THEN move on to the next step.)

Jan 25, 2006 7:57 AM in response to Arkouda

Replying to you earlier set me thinking about this again, and I think I have the answer:

If you check for "complete" before the remote site has started to send data, it will test TRUE. So what I did was to use the JavaScript "document.title" as another condition. (Incidentally, if Safari shows "Untitled" in the Window, this tests as a null string "") As soon as the remote site starts to send, the loaded state will change from "complete" and the window title will have contents.

(In pseudocode: IF your window title is NOT "" AND your loaded state is "complete" THEN move on to the next step.)

Jan 25, 2006 2:26 PM in response to Arkouda

Bernard

I think you on the right track.

The only problem is the web site I'm using named all the pages the same in the title.

I get a "Loading "Title of Page"" and when complete the Loading goes away.
When I do a "document.title" while the page is loading the return doesn't contain the word loading. It just gives me the page title which is the same as the previous page.

Good thinking though and I appreciate you ideas.

Thanks

Marshall

Jan 25, 2006 2:51 PM in response to macBidder

It's a shame they named all pages the same. (I am glad Apple doesn't do it here, otherwise I would have problem with auto-logins!)

I think the only option that you have then is to put a sufficiently long delay at the beginning of the subroutine to ensure that the remote site has time to respond. Of course that's not a precise thing, and will not cope with all connection speeds, but it will at least prevent the original problem of which you complained.

Remember, however, that if you are starting from a blank page and loading the first of your site's pages, you will be able to use this trick to spot the conjunction of a page that is not entitled "" and has loaded.

Safari Page Loaded

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.