By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,628 Members | 1,880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,628 IT Pros & Developers. It's quick & easy.

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

P: 3
Hi.

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:

www.google.com
www.bbc.co.uk
www.digg.com

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
etc

Can someone please help me with this very basic script!
Jun 19 '07 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,390
... 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

P: 3
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...

www.oursite.com/index.jsp
www.oursite.com/categories.jsp
www.secure.oursite.com/checkout.jsp

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

window.onLoad

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

gits
Expert Mod 5K+
P: 5,390
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

P: 3
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

gits
Expert Mod 5K+
P: 5,390
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.