Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to wait for the last frame, or.... 1

Status
Not open for further replies.

realtree

Technical User
Aug 5, 2003
53
CA
...something.
I have a frame with an onLoad handler that references another frame (parent.frames('main').location). The former frame loads first, then a 'menu' frame, then the 'main' frame. The problem is that when moving from any non-frames page to any of the 'main' pages (either from the non frames title page, or by using the 'back' button), the 1st frame is trying to refer to the 3rd frame that hasn't loaded yet. It's not a problem when moving around within the frames part of the site. Is there a way I can wait for the 3rd frame to load before the 1st frame runs its onLoad event?

I tried moving the onLoad to the <frameset>, but then I realized that this does nothing unless init_***.html is reloaded. My init_***.html pages are only used from the main title page to create the frames, and to reload in case the page isn't in its proper parent frameset.

I hope I described this clearly enuf...
 
Sorry, maybe I wasn't very clear. It's quite complicated in a sense...

I need a way for frame1 to wait until frame3 is loaded, so I can refer to parent.frame3.location from a script in the first frame. The problem is that parent.frame3 doesn't even exist yet.

Using onLoad from the <frameset> doesn't work because the frames page is only loaded when:

1: frame3 discovers that it's not in a frame,
2: a link is clicked from the title page, or
3: the back button is used to return to the site

All 3 of the above actions results in the frames page being reloaded. Pressing the back button does not.

frame1 checks if frame3's content matches frame1, and if it doesn't, then frame3.location='the_proper_page.html'.

example:
Code:
______________      ______________      ______________
|    FAQ     |      |    FAQ     |      |  Sitemap   |   frame1
|------------|      |------------|      |------------|
|    Menu    |      |    Menu    |      |    Menu    |   frame2
|------------|      |------------|      |------------|
|  Q: Why?   |  ->  |            |  ->  |            |  ->
|  A: Bcuz!  |      |  Sitemap   |      |  Sitemap   |
|____________|      |____________|      |____________|   frame3
 link clicked       sitemap.html         frame3 fixed
                preforms onLoad="if.."
===============================================================
______________      ______________      ______________
|    FAQ     |      |    FAQ     |      |    FAQ     |   frame1
|------------|      |------------|      |------------|
|    Menu    |      |    Menu    |      |    Menu    |   frame2
|------------|      |------------|      |------------|
|            |  ->  |            |  ->  |  Q: Why?   |
|  Sitemap   |      |  Sitemap   |      |  A: Bcuz!  |
|____________|      |____________|      |____________|   frame3
 back button        top_faq.html         frame3 fixed
   pressed      preforms onLoad="if.."

Sorry if I'm being redundant, but I'm obsessed!

Sidebar:
Is there a difference between [red]parent.main.location='blah.html'[/red] and [red]parent.main.location.replace('blah.html')[/red]?
 
try using timers:
function DetectFrame3()
{
if(typeof(parent.frames.Frame3Name)=="undefined")
{
setTimeout("DetectFrame3()",1000)
return false
}
else
{
//Call your function that accesses Frame3
}
}

Known is handfull, Unknown is worldfull
 
I think you've almost solved it! DetectFrame3, oddly enuf, doesn't actually detect frame3, well it does, but there's no way of knowing how long it's going to take to download the page. What if I were to to something like this instead?

Code:
function DetectFrame3()
{
  while(typeof(parent.frames.Frame3Name)=="undefined")
  {
    *?*
  }
 }

so that it waits until the page is loaded, instead of just waiting a preset amount of time...

but wait... I used onLoad="alert(typeof(parent.frames.Frame3Name)) to test and it does return undefined like expected, but then i also added a button that alerts, so I can see what it looks like once it's loaded.. it still returns undefined...
I think what you have is very close. A test if the frame is there without causing an error by referring to a not-yet-existant object.

A little voice in the back of my mind is telling me there's a better way to do this, an entirely different approach. Too bad the little voice is more of a philosopher than a programmer.
 
oh. nevermind. i'm an idiot. :p

i forgot to change the parent.frames.Frame3Name to parent.frames['main']

i wasn't aware that parent.frames.main exists. I know about parent.main, and parent.frames['main']

...I'm a greenhorn
 
function DetectFrame3()
{
while(typeof(parent.frames.Frame3Name)=="undefined")
{
*?*
}
}

is very risky, it so happens that when the while loop executes nothing else works, therefore the page might get stuck in an infinite loop.

if u feel the time interval is too much reduce the delay time:
setTimeout("DetectFrame3()",100)

i think this is the only way out...



Known is handfull, Unknown is worldfull
 
then keep me updated... ;)

Known is handfull, Unknown is worldfull
 
brilliant!!!

in frame3's onload function the Frame1's function is called. that will eliminate the Frmae3 not loading (as its in the frame3's onload function)...

Known is handfull, Unknown is worldfull
 
Well, it seems to work quite well. All I've learned these past few days - This is the product. Not perfect, but I've come this far already - why not...?

top_sitemap.html
Code:
<script language="javascript">
<!--
function FirstOpen() {
 if (typeof(parent.frames['main']) == "object") {
  DetectMain();
 }
}

function DetectMain() {
 if (parent.frames['main'].location != 'file:///S:/Website%20Development/sitemap.html') {
  parent.frames['main'].location.replace('sitemap.html');
 };
}
//-->
</script>

<body onLoad="FirstOpen();">

sitemap.html
Code:
<script language="javascript">
<!--
function Top() {
 parent.frames['topguh'].DetectMain();
}

function DetectTop() {
 if ((top == null) || (top == self)) {
  top.location='init_webs.html';
 }
 else if (parent.frames['topguh'].location != 'file:///S:/Website%20Development/top_sitemap.html') {
  parent.frames['topguh'].location.replace('top_sitemap.html');
 };
}
//-->
</script>

<body onLoad="Top();DetectTop();">

And now it's time to go home...
 
And now it's time to end this thread for good. It turns out that my whole problem was solved with one word:

"replace"

I drew up a flowchart of sorts to figure out exactly what's happening amidst all the confusion, clean up the code, and to figure out where to start on getting rid of this strange 'blinking' (pages re-reloading?). That's when I started to realize that something seemed redundant, then something else... In the end, I ended up deleting all JS code from the frame1 pages, and trimmed the frame3 pages down to this:

Code:
<script language="javascript">
<!--
function DetectTop() {
 if ((top == null) || (top == self)) {
  top.location='init_webs.html';
 }
 else if (parent.frames['topguh'].location != 'file:///S:/Website%20Development/top_sitemap.html') {
  parent.frames['topguh'].location.replace('top_sitemap.html');
 };
}
//-->
</script>

<body onLoad="DetectTop();">
I can't say I didn't learn anything.
I'm sure it will come in handy...
 
Congratulations, glad we can now put it to rest [lol]

[machinegun] This Thread: thread216-998852

-kaht

Weaseling out of things is important to learn. It's what separates us from the animals... except the weasel. - Homer Simpson (no, I'm not Homer)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top