Loading web page - checking that it’s completely done

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
hairydalek
Posts: 57
Joined: Sat Feb 01, 2014 8:57 pm

Loading web page - checking that it’s completely done

Post by hairydalek » Sat Mar 22, 2014 9:20 pm

My GPS tracking to movie project (see my previous post about number accuracy) is going along nicely. An example of the output is here:
http://www.youtube.com/watch?v=WxizVm66TII

You’ll notice a couple of problems with it. Firstly, my screen saver kicked in and it grabbed a frame of that (oops).

The other problems is that in places, the map has not fully loaded, so you get the odd grey square. I’d like to be able to detect that the whole thing has loaded before the screen grab is taken.

The scrips works like this:

Calculates the lat & long to display

Loads an HTML file (stored locally) which is populated with necessary data

Saves in the temporary folder using specialFolderPath("temporary")

Opens this as a URL and then takes a screen shot

The HTML file is this:

Code: Select all

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe width="__width__" height="__height__" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://www.google.com/maps?t=h&ie=UTF8&ll=__lat__,__long__&spn=0.001173,0.002607&z=__zoom__&output=embed"></iframe>
</body>
</html>
You’ll see lace holders for the data from the LiveCode application.

I am using some delaying code that I believe checks that the page has loaded, but I’m not so sure it’s actually working too well.

Code: Select all

revBrowserSet gBrowserId, "rect" , rect of graphic "Browser Rect Graphic" 
         revBrowserSet gBrowserId , "url" , displayHTML & "?"
         revBrowserSet gBrowserId , "scrollbars" , "false"
         
         put  rect of graphic "Browser Rect Graphic"  into imageSize
         
 -- Check to see if the browser has loaded
         put "" into tIAmBusy
         put revBrowserGet (gBrowserId, "busy") into tIAmBusy
         repeat until not tIAmBusy
            put revBrowserGet (gBrowserId, "busy") into tIAmBusy
            if not tIAmBusy then exit repeat
            wait 1200 milliseconds
         end repeat
         
         wait 2400 milliseconds with messages

--carry on to do screen shot things…
gBrowser ID is the ID of a graphic item which loads the browser display.

The original code which I found online had a much smaller delay - but I decided to increase it and add a extra 2400 milliseconds for good measure, just in case. Now, I am aware that I’m loading a Google map, and that this may cause unexpected behaviour. However, I’d be interested to know if there is a more robust way of detecting that an HTML page has finished loading before taking the screen shot.

Other than this little niggle, it’s all coming together rather nicely.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Loading web page - checking that it’s completely done

Post by Simon » Sun Mar 23, 2014 1:02 am

browserDocumentComplete?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Loading web page - checking that it’s completely done

Post by Dixie » Sun Mar 23, 2014 1:34 am

hairydalek.. (Jesus!... what a handle :D )

put revBrowserGet(browserId, "busy") into whatsHappening... busy should return true if the browser is doing something and false if it isn't. There are lots of things that 'revBrowserGet' will check, have a look at the entry in the dictionary..

Post Reply