8 Replies Latest reply: Jan 25, 2006 7:29 PM by macBidder
macBidder Level 1 Level 1 (0 points)
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)
  • Justin S. Level 3 Level 3 (655 points)
    Hi MacBidder,

    Maybe this post will help you out. Good Luck!
    --Justin S.
  • macBidder Level 1 Level 1 (0 points)
    Thanks for replying

    I did a search before writing this and yes I saw that post. It deals with the document.readystate java line.

    This works halfway as it returns a "complete" when the page connects, not complete as the term would indicate.

    Thanks again for trying.

    Marshall
  • Bernard Harte Level 4 Level 4 (3,165 points)
    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 pageloaded(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.
  • Bernard Harte Level 4 Level 4 (3,165 points)
    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.)
  • Bernard Harte Level 4 Level 4 (3,165 points)
    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.)
  • macBidder Level 1 Level 1 (0 points)
    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
  • Bernard Harte Level 4 Level 4 (3,165 points)
    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.
  • macBidder Level 1 Level 1 (0 points)
    I guess I could take a quick grab of the html source in each loop. There are some unique words on one page compared to another. Just keep looping until that word is contained in the page source.

    Thanks again Bernard for you time trying to help.

    Marshall