Question : Execute javascript functions consecutively

In my script I need to do the following

Refresh Iframe with some parameters.
Within iframe content there is a div with some information important for the next function
Pick up this content and use it in the next javascript statement.

function Do() {
RefreshIframe();
PickUpData();
UseData();
}.

The problem is that when I run Do() javascript begins to execute second and third statement before iframe were loaded. So PickUpData does not find needed content and so USeData() does not work.

Of course I can set timeout after RefreshIframe();
But there should be a better way. Something like ready() for main document.
Suggestion?

Answer : Execute javascript functions consecutively

The following lines will not work
iframe.onload = function(){
//code lines
}

But if you attack the event with a listener it will work, try this: (tested on IE6)
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
<html> 
<script type="text/javascript">

onload = function(){
	eventPush(document.getElementById('myiframe'),'load',function () {myFrameOnloadFunction();});
	document.getElementById('myiframe').src = 'http://www.google.com'
}

function eventPush(obj, event, handler) {
  if (obj.addEventListener) {
    obj.addEventListener(event, handler, false);
  } else if (obj.attachEvent) {
    obj.attachEvent('on'+event, handler);
  }
}
 
function myFrameOnloadFunction(){
	alert('iframe loaded')
}

</script>
 <body>
  <iframe id="myiframe"></iframe>
 </body>
</html>
Random Solutions  
 
programming4us programming4us