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

Frames, windows, functions & onload

P: n/a
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

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <lr*@hotpop.com> wrote in message
news:el**********@hotpop.com...
Da Costa Gomez <dc*@xs4all.nl> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #2

P: n/a
Da Costa Gomez <dc*@xs4all.nl> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

P: n/a
Lasse Reichstein Nielsen wrote:
Da Costa Gomez <dc*@xs4all.nl> writes:

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

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.