Frames, windows, functions & onload

D

Da Costa Gomez

Hi all,

I've been eluded the last couple of *days* on the onload mystery within
the frame and function context.
Problem is as follows:
- frameset with two frames. One called scripts and the other called main
- scripts carries a bunch of js functions rechable via
parent.scripts.functioName()
- Main carries the html page that utilizes some functions

All is well until I start using the onload event.
Situation:
1. Main uses an onclick that calls a startFunction() which loads a page
back into main.
2. Since I want this new page to be loaded *before* I go into the next
function I figured setting parent.main.onload = function2bCalled whilst
going into the startFunction() would do the trick.

Not so!! It sets the parent.main.onload allright but after
parent.main.location.href="newPage.html" it does NOT go into
function2bCalled().

Does anybody have a clue as to what is going on here? I'm nearing my
gaga point.

TIA,
Fermin DCG
 
P

Peter

In addition to this, you could set the src of the main frame in your
frameset to be a blank page (blank.htm, blank.asp or whatever it is you're
doing).

Then from within the script frame onLoad event do something like this

top.mainFrame.document.location.replace "main.htm"

This ensures that your script frame has definitely finished loading before
you try to call anything from within the main frame.

Peter.

Lasse Reichstein Nielsen said:
Da Costa Gomez said:
2. Since I want this new page to be loaded *before* I go into the next
function I figured setting parent.main.onload = function2bCalled
whilst going into the startFunction() would do the trick.


Not so!! It sets the parent.main.onload allright but after
parent.main.location.href="newPage.html" it does NOT go into
function2bCalled().

As you explain it, it sounds like you set the window's onload handler
before setting the href. Loading a new page gives a new global
javascript object, i.e., a new window object, so the onload handler is
long gone when the page is loaded.
Does anybody have a clue as to what is going on here? I'm nearing my
gaga point.

You can try this as a test:

parent.frames['main'].foo = 42;
parent.frames['main'].location.href="newPage.html";
alert(parent.frames['main'].foo);

It should turn out to alert "undefined". The same goes for your
onload handler.

I think your best chance is to let "newPage.html" have its own
onload handler, which can then call a function you have set up
in advance. E.g.

parent.frames['script'].callback = function2bCalled;
parent.frames['main'].location.href="newPage.html";

and then "newPage.html"'s onload handler calls

parent.frames['script'].callback();

/L
 
L

Lasse Reichstein Nielsen

Da Costa Gomez said:
Strangely enough though the example you gave:
parent.frames['main'].foo = 42;
parent.frames['main'].location.href="newPage.html";
alert(parent.frames['main'].foo);

went along fine, no errors (which surprised me a little bit but then
again, who cares).

Was the "newPage.html" already in the main frame? When I tested it
twice in a row, so the href wasn't really changed, the global object
wasn't reset either.
I tested it in Opear, not sure if IE has subtle differences.

/L
 
D

Da Costa Gomez

Lasse said:
Strangely enough though the example you gave:
parent.frames['main'].foo = 42;
parent.frames['main'].location.href="newPage.html";
alert(parent.frames['main'].foo);

went along fine, no errors (which surprised me a little bit but then
again, who cares).


Was the "newPage.html" already in the main frame?
Tested it with both there and not there, no problems.
When I tested it
twice in a row, so the href wasn't really changed, the global object
wasn't reset either.
I tested it in Opear, not sure if IE has subtle differences.
I basically use Mozilla Firebird (switched away from Opera) and IE (to
test). IE is rather boring when it comes to popping windows though.
Seems to have a diff format from open(url, "title") (which works fine in
Opera as wel as FireBird).

Cheers,
Fermin DCG
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top