471,093 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,093 software developers and data experts.

Newbie: Make a script wait for a full page to load JS/Chickenfoot


This is driving me crazy so I hope someone will help!

I am using chickenfoot and javascript to try and achieve something that should be really simple.

Basically a script that navigates through a series of preset URL's in order to populate the caches of our website.

so for ease lets say it has to surf through:


My problem is that the script just races ahead to the last link without waiting for the 1st two pages to load completely.
Now with chickenfoot (which is a firefox extension that basically extends the javascript API) I could use a (sleep) command between them. But the pages concerned could take 1 second or 90 seconds to load depending on the circumstances so setting a sleep is not very reliable.

so what I want is basically
load page1
wait for page to load fully
load page 2
wait for page to load fully
load page 3
wait for page to load fully

Can someone please help me with this very basic script!
Jun 19 '07 #1
5 4110
5,390 Expert Mod 4TB
... whoww ... that is much less basic as you might think ;)) ... until you load pages that are not your own (google.com, ...) you would have a problem with that ... knowing when the pages are ready might be possible for you with an onload of an iframe or frame wherever you load that page ... BUT: at the moment i'm not sure there is such a handler for frames? perhaps there might be something like a ready-state for a frame that you may ask for a change or something? ... i'll have a look at this in the evening today ... perhaps somebody has an other solution?

kind regards ...
Jun 19 '07 #2
Hi and thanks for the reply.

Just to be clear, these are our webpages but I just used the above URL's to protects some technically vunerable links :)

So lets say instead...


etc :)

I tell you what I have stumbled upon so far.

One is an onLoad method that is built into Chickenfoot but its very poorly documented and doesnt seem to work as you would expect.

Then their is
window.addEventListener("load",function() { progress.init(); }, false);

which I just don't understand lol

followed by something like


all of which is stretching my meagre JS skills to their limit and then some :)
I guess I am stuggling with putting these pieces together in a logical and correct manner. My programming experience is all from an earlier era (basic lol) and things were single threaded and very simple in those days. I am not good at building up this complexity of code.... sad isn't it!
Jun 19 '07 #3
5,390 Expert Mod 4TB
hmmm ... in this case there are simple ways ... to do that ... don't know what you have so far, but the main idea is: every page you load registers a counter or whatever in its own onload-event in that page where you want to start your script. when the counter matches a condition that you want to have fullfilled ... then start the processing of your script (something like: counter == 3 or whatever) ... you may setInterval and pull this information or you may trigger your execution from the onloads of your pages to load too ... that means ... one page registers onload in the parent page, asks for the counter-condition, calls the script in the parent that you want to have executed ...

hope this makes the idea clear?

kind regards ...
Jun 19 '07 #4
Your explanation is great, I know exactly what I want to do in my head... but getting it down in functional code form is (as always for me!!) the problem.

One important thing that maybe I haven't made clear is that this code does not reside in the pages themselves. Its an external script that chickenfoot firefox extension runs in the sidebar. So I think I have to do some naming of windows etc too I think.

In the head it sounds like this:

//configurables for the user to change parts of the url depending on which site they want to presurf
var leg = "webserver1";
// cc - the country code which the user wishes to presurf
var cc = "gb";
// lc - the language code which the user wishes to presurf
var lc = "en";

// non configurables
var windowname="window1"
var counter =0

// progress() a simple progress output for debugging and logging information
function progress() {
var currentUrl = window.location.href;
output(currentUrl+" has loaded");
// add +1 to counter

//running code

if counter = 0 then
window.location = "http://"+leg+".ourcompany.com/"+cc+"/"+lc+"/catalog/14369/";
window.onLoad = progress;
else exit

if counter = 1 then
window.location = "http://"+leg+".ourcompany.com/"+cc+"/"+lc+"/product/40825717";
window.onLoad = progress;
else ????????????????????

etc etc ??

Once the code is all complete I aim to package it all into a nice FF extension that the user can install and then set the variables through a nice little pop-up (ahhh dialogs.... another can of worms for me to get into later!!)
Jun 20 '07 #5
5,390 Expert Mod 4TB
may be ...i don't know the chickenfoot extension ... but one thing to notice:

to do a comparison in javascript you usually use:

Expand|Select|Wrap|Line Numbers
  1. if (variablevalue == something) {
  2. }
else you do an assignment ... ;) don't know whether cickenfoot works the same way or not?

kind regards ...
Jun 20 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Ed Brandmark | last post: by
2 posts views Thread by Ola Fjelddahl | last post: by
4 posts views Thread by Dennis M. Marks | last post: by
7 posts views Thread by cjl | last post: by
4 posts views Thread by Stephajn Craig | last post: by
reply views Thread by janetb | last post: by
3 posts views Thread by parkpost | last post: by
2 posts views Thread by GiJeet | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.