views:

39

answers:

2

My website consists of two frames, let's say upperFrame and lowerFrame.

On the document ready of the page in lowerFrame, it access one of textbox located on the page of upperFrame. Sometimes, since the upperFrame do NOT complete its loading, lowerFrame get the undefined while it access the upperFrame.

Let me know if there are Any solutions/checking to prevent this problem?

+2  A: 

How about updating 2 vars in the parent of both frames: topReady and bottomReady. At the top and at the lower frames you set them to call a function that checks if both of them are true. If not it sets the appropriate var to true and once the 2nd frame will be calling the function it will trigger whatever action you want to.

Edit: Another option is to try and use

$(window.parent.upperFrame).ready(function(){
  alert('upperFrame loaded')
});
IgalSt
Thanks..it's relevant solution..but it's NOT okay for me because I need all the work to happen on the lower frame(on upper frame,I just need to check the value of that textbox)..If I follow this solution, I need to check it again which frame actually calls in that function and, based on that,in the function, I have to handle in two different ways..Anyways, Thanks for the decent idea..
Kai
@Kai: Check my edit.. I think this is your solution.
IgalSt
Yes..But, At that time,maybe the lowerframe(current document) will NOT complete loading??How can I check for it???
Kai
Anyway, +1 for the solution..
Kai
One the lower frame is loaded it will run the code (from the "edit" of my solution) and "wait for the upperFrame to load (if it was already loaded if will execute the script right away).
IgalSt
+2  A: 

try jQuery .load() function

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

Here is the sample code

Edited:
put code below in document ready of lower iframe.

  $(function(){
   $('#UpperIframeID', window.parent.document).load(function(){  
        var valueOFTextbox = (this).contents().find("#textboxID").val();                                 
   });
 });
   </script>

If it doesn't work in IE then put conditional statement and for IE use .ready() function.

Ayaz Alavi
:) nope...load() function can NOT be used in this case..
Kai
why not, just put that code in main document and fill in value of textbox in loweriframe by fetching it from load function of upperiframe
Ayaz Alavi
Ahh..yes..it's relevant ...but, I have to write the function on the document of lower frame because all the work should take place on the lower frame's document..Again, Pages will change from time to time (too often) on the lower frame.If I follow that way, I have to check again which pages are currently shown in the lower frame.(In some document, I do want this function). Anyway, thanks a lot for the idea.
Kai
Anyway, +1 for the solution..
Kai
Also,it will NOT work if the page(document) in the lower frame change.Willn't it??
Kai
If you are inserting that code in lower iframe then put this code in its document ready. You have to catch that event when contents in the lower iframe changes and see whether upperiframe is loaded or not but since you need to insert this code in lower iframe then you can put it in document ready function
Ayaz Alavi
Thanks!!! It works !!!
Kai