JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Page load complete? Posted by compuchip on 17 Jul 2003 at 10:46 AM
I'd written this message before, but forgot to click Post, just Preview and then closed my browser. So here it goes again :)

I have one visible frame (output) and one hidden frame (process).
output contains this code (actually it doesn't - this is an example to illustrate my point)
 function writeOut(text) { document.write(text); }
 writeOut("1- Starting your calculation");
 parent.process.location.href = "calculate.pl?command=3+5";
 // xxx
 writeOut("4- That's all folks. You can try again if you want");
 // ... some more writeouts ...


The output in the invisible frame will be
<SCRIPT>parent.output.writeOut("2- Calculating: 3 + 5"); parent.output.writeOut("3- The result is <b>8</b>");</SCRIPT>

The only problem is, that the lines are output in the order 1 - 4 - 2 - 3. So obviously line 4 is printed before the (quite large) .pl-script has been completely loaded and gets the chance to print it's lines.
Of course I can work around this by putting all lines from the 2nd writeOut and downwards in a separate function (footerText()) which is then called by the Perl-script after the result of the calculation has been printed, but I'd rather just replace the 'xxx' with some code that waits for the Perl-script to complete.

Hope you can help. I tried several tricks with parent.output (like .loaded and .readyState) but they all yield an 'undefined'
Report
Re: Page load complete? Posted by lillu on 21 Jul 2003 at 2:14 AM
Hi,

To check:

1. If the page has fully loaded (including images)
This can be done with <body onload="dosomefunction()"> because the onload only fires when the page is completely loaded so all the elements are there you want to execute your functions on.

2. If the inline javascript has fully loaded
This can be done by putting alert('Script loaded'); in the top of your inline javascript as the full script must have been parsed to get this alert message.

3. If the external javascript file has fully loaded.
That is the readyState thing I copied from the msdn site. Haven't used it but did the aforementioned two things; they are simple and they worked fine for my purposes.

<script language="JavaScript"
id=SomeFile src="somefile.js"></script>
<script language="JavaScript">

function useStuffInSomeFile() {
}

if (SomeFile.readyState == "complete" ) {
useStuffInSomeFile() {
} else {
SomeFile.onreadystatechange = ifComplete;
}

function ifComplete() {
if (SomeFile.readyState == "complete") {
SomeFile.onreadystatechange = null;
useStuffInSomeFile();
}
}
</script>

HTH,

Lillu

: I'd written this message before, but forgot to click Post, just Preview and then closed my browser. So here it goes again :)
:
: I have one visible frame (output) and one hidden frame (process).
: output contains this code (actually it doesn't - this is an example to illustrate my point)
:
:  function writeOut(text) { document.write(text); }
:  writeOut("1- Starting your calculation");
:  parent.process.location.href = "calculate.pl?command=3+5";
:  // xxx
:  writeOut("4- That's all folks. You can try again if you want");
:  // ... some more writeouts ...
: 

:
: The output in the invisible frame will be
: <SCRIPT>parent.output.writeOut("2- Calculating: 3 + 5"); parent.output.writeOut("3- The result is <b>8</b>");</SCRIPT>
:
: The only problem is, that the lines are output in the order 1 - 4 - 2 - 3. So obviously line 4 is printed before the (quite large) .pl-script has been completely loaded and gets the chance to print it's lines.
: Of course I can work around this by putting all lines from the 2nd writeOut and downwards in a separate function (footerText()) which is then called by the Perl-script after the result of the calculation has been printed, but I'd rather just replace the 'xxx' with some code that waits for the Perl-script to complete.
:
: Hope you can help. I tried several tricks with parent.output (like .loaded and .readyState) but they all yield an 'undefined'
:

Report
Re: Page load complete? Posted by lillu on 21 Jul 2003 at 3:07 AM
Hi again,

Sorry, I forgot you worked with frames...

Well basically this will not change the concept but as you want both frames loaded (process first and output second)

To check:

1. If the complete frameset has loaded (the first time only, when changing individual frames later it will not work) put this into your index page or where you define your frames:

<frameset onload="alert('Frames loaded');">
<frames src="process.htm" name="process">
<frames src="output.htm" name="output">
</frameset>

2. If the individual frame has loaded

a, Define a global variable in the frameset page.
<script language="javascript">
var loaded = false;
</script>
b, Put this into the output.htm:
<body onload="loaded = true">
c, Put this into the process.htm:
<script language="javascript">
if parent.output.loaded == true
{ }
</script>

or

<script language="javascript">
if (typeof (parent.output.loaded != "undefined"))
{ process calculations here }
</script>

Get back to me how it works...

Thanx,

Lillu

: I'd written this message before, but forgot to click Post, just Preview and then closed my browser. So here it goes again :)
:
: I have one visible frame (output) and one hidden frame (process).
: output contains this code (actually it doesn't - this is an example to illustrate my point)
:
:  function writeOut(text) { document.write(text); }
:  writeOut("1- Starting your calculation");
:  parent.process.location.href = "calculate.pl?command=3+5";
:  // xxx
:  writeOut("4- That's all folks. You can try again if you want");
:  // ... some more writeouts ...
: 

:
: The output in the invisible frame will be
: <SCRIPT>parent.output.writeOut("2- Calculating: 3 + 5"); parent.output.writeOut("3- The result is <b>8</b>");</SCRIPT>
:
: The only problem is, that the lines are output in the order 1 - 4 - 2 - 3. So obviously line 4 is printed before the (quite large) .pl-script has been completely loaded and gets the chance to print it's lines.
: Of course I can work around this by putting all lines from the 2nd writeOut and downwards in a separate function (footerText()) which is then called by the Perl-script after the result of the calculation has been printed, but I'd rather just replace the 'xxx' with some code that waits for the Perl-script to complete.
:
: Hope you can help. I tried several tricks with parent.output (like .loaded and .readyState) but they all yield an 'undefined'
:

Report
Re: Page load complete? Posted by compuchip on 21 Jul 2003 at 4:44 AM
Thanks, I'll try it. The 2nd one is probably what I was looking for

: Hi again,
:
: Sorry, I forgot you worked with frames...
:
: Well basically this will not change the concept but as you want both frames loaded (process first and output second)
:
: To check:
:
: 1. If the complete frameset has loaded (the first time only, when changing individual frames later it will not work) put this into your index page or where you define your frames:
:
: <frameset onload="alert('Frames loaded');">
: <frames src="process.htm" name="process">
: <frames src="output.htm" name="output">
: </frameset>
:
: 2. If the individual frame has loaded
:
: a, Define a global variable in the frameset page.
: <script language="javascript">
: var loaded = false;
: </script>
: b, Put this into the output.htm:
: <body onload="loaded = true">
: c, Put this into the process.htm:
: <script language="javascript">
: if parent.output.loaded == true
: { }
: </script>
:
: or
:
: <script language="javascript">
: if (typeof (parent.output.loaded != "undefined"))
: { process calculations here }
: </script>
:
: Get back to me how it works...
:
: Thanx,
:
: Lillu
:
: : I'd written this message before, but forgot to click Post, just Preview and then closed my browser. So here it goes again :)
: :
: : I have one visible frame (output) and one hidden frame (process).
: : output contains this code (actually it doesn't - this is an example to illustrate my point)
: :
: :  function writeOut(text) { document.write(text); }
: :  writeOut("1- Starting your calculation");
: :  parent.process.location.href = "calculate.pl?command=3+5";
: :  // xxx
: :  writeOut("4- That's all folks. You can try again if you want");
: :  // ... some more writeouts ...
: : 

: :
: : The output in the invisible frame will be
: : <SCRIPT>parent.output.writeOut("2- Calculating: 3 + 5"); parent.output.writeOut("3- The result is <b>8</b>");</SCRIPT>
: :
: : The only problem is, that the lines are output in the order 1 - 4 - 2 - 3. So obviously line 4 is printed before the (quite large) .pl-script has been completely loaded and gets the chance to print it's lines.
: : Of course I can work around this by putting all lines from the 2nd writeOut and downwards in a separate function (footerText()) which is then called by the Perl-script after the result of the calculation has been printed, but I'd rather just replace the 'xxx' with some code that waits for the Perl-script to complete.
: :
: : Hope you can help. I tried several tricks with parent.output (like .loaded and .readyState) but they all yield an 'undefined'
: :
:
:

Report
Re: Page load complete? Posted by lillu on 21 Jul 2003 at 6:52 AM
Hi,

Oh, I made a typo ...

of course it's <frame src="" ...



Hope you haven't tried it and got nice grey windows...

: <frameset onload="alert('Frames loaded');">
: <frames src="process.htm" name="process">
: <frames src="output.htm" name="output">
: </frameset>


: Thanks, I'll try it. The 2nd one is probably what I was looking for
:
: : Hi again,
: :
: : Sorry, I forgot you worked with frames...
: :
: : Well basically this will not change the concept but as you want both frames loaded (process first and output second)
: :
: : To check:
: :
: : 1. If the complete frameset has loaded (the first time only, when changing individual frames later it will not work) put this into your index page or where you define your frames:
: :
: : <frameset onload="alert('Frames loaded');">
: : <frames src="process.htm" name="process">
: : <frames src="output.htm" name="output">
: : </frameset>
: :
: : 2. If the individual frame has loaded
: :
: : a, Define a global variable in the frameset page.
: : <script language="javascript">
: : var loaded = false;
: : </script>
: : b, Put this into the output.htm:
: : <body onload="loaded = true">
: : c, Put this into the process.htm:
: : <script language="javascript">
: : if parent.output.loaded == true
: : { }
: : </script>
: :
: : or
: :
: : <script language="javascript">
: : if (typeof (parent.output.loaded != "undefined"))
: : { process calculations here }
: : </script>
: :
: : Get back to me how it works...
: :
: : Thanx,
: :
: : Lillu
: :
: : : I'd written this message before, but forgot to click Post, just Preview and then closed my browser. So here it goes again :)
: : :
: : : I have one visible frame (output) and one hidden frame (process).
: : : output contains this code (actually it doesn't - this is an example to illustrate my point)
: : :
: : :  function writeOut(text) { document.write(text); }
: : :  writeOut("1- Starting your calculation");
: : :  parent.process.location.href = "calculate.pl?command=3+5";
: : :  // xxx
: : :  writeOut("4- That's all folks. You can try again if you want");
: : :  // ... some more writeouts ...
: : : 

: : :
: : : The output in the invisible frame will be
: : : <SCRIPT>parent.output.writeOut("2- Calculating: 3 + 5"); parent.output.writeOut("3- The result is <b>8</b>");</SCRIPT>
: : :
: : : The only problem is, that the lines are output in the order 1 - 4 - 2 - 3. So obviously line 4 is printed before the (quite large) .pl-script has been completely loaded and gets the chance to print it's lines.
: : : Of course I can work around this by putting all lines from the 2nd writeOut and downwards in a separate function (footerText()) which is then called by the Perl-script after the result of the calculation has been printed, but I'd rather just replace the 'xxx' with some code that waits for the Perl-script to complete.
: : :
: : : Hope you can help. I tried several tricks with parent.output (like .loaded and .readyState) but they all yield an 'undefined'
: : :
: :
: :
:
:

Report
Re: Page load complete? Posted by compuchip on 21 Jul 2003 at 9:26 AM
lol, I'd just looked at the key of the solution and then applied it to my project. I didn't even notice the typo yet :)

: Hi,
:
: Oh, I made a typo ...
:
: of course it's <frame src="" ...
:
:
:
: Hope you haven't tried it and got nice grey windows...
:
: : <frameset onload="alert('Frames loaded');">
: : <frames src="process.htm" name="process">
: : <frames src="output.htm" name="output">
: : </frameset>
:
:
: : Thanks, I'll try it. The 2nd one is probably what I was looking for
: :
: : : Hi again,
: : :
: : : Sorry, I forgot you worked with frames...
: : :
: : : Well basically this will not change the concept but as you want both frames loaded (process first and output second)
: : :
: : : To check:
: : :
: : : 1. If the complete frameset has loaded (the first time only, when changing individual frames later it will not work) put this into your index page or where you define your frames:
: : :
: : : <frameset onload="alert('Frames loaded');">
: : : <frames src="process.htm" name="process">
: : : <frames src="output.htm" name="output">
: : : </frameset>
: : :
: : : 2. If the individual frame has loaded
: : :
: : : a, Define a global variable in the frameset page.
: : : <script language="javascript">
: : : var loaded = false;
: : : </script>
: : : b, Put this into the output.htm:
: : : <body onload="loaded = true">
: : : c, Put this into the process.htm:
: : : <script language="javascript">
: : : if parent.output.loaded == true
: : : { }
: : : </script>
: : :
: : : or
: : :
: : : <script language="javascript">
: : : if (typeof (parent.output.loaded != "undefined"))
: : : { process calculations here }
: : : </script>
: : :
: : : Get back to me how it works...
: : :
: : : Thanx,
: : :
: : : Lillu
: : :
: : : : I'd written this message before, but forgot to click Post, just Preview and then closed my browser. So here it goes again :)
: : : :
: : : : I have one visible frame (output) and one hidden frame (process).
: : : : output contains this code (actually it doesn't - this is an example to illustrate my point)
: : : :
: : : :  function writeOut(text) { document.write(text); }
: : : :  writeOut("1- Starting your calculation");
: : : :  parent.process.location.href = "calculate.pl?command=3+5";
: : : :  // xxx
: : : :  writeOut("4- That's all folks. You can try again if you want");
: : : :  // ... some more writeouts ...
: : : : 

: : : :
: : : : The output in the invisible frame will be
: : : : <SCRIPT>parent.output.writeOut("2- Calculating: 3 + 5"); parent.output.writeOut("3- The result is <b>8</b>");</SCRIPT>
: : : :
: : : : The only problem is, that the lines are output in the order 1 - 4 - 2 - 3. So obviously line 4 is printed before the (quite large) .pl-script has been completely loaded and gets the chance to print it's lines.
: : : : Of course I can work around this by putting all lines from the 2nd writeOut and downwards in a separate function (footerText()) which is then called by the Perl-script after the result of the calculation has been printed, but I'd rather just replace the 'xxx' with some code that waits for the Perl-script to complete.
: : : :
: : : : Hope you can help. I tried several tricks with parent.output (like .loaded and .readyState) but they all yield an 'undefined'
: : : :
: : :
: : :
: :
: :
:
:

Report
Re: Page load complete - final Posted by lillu on 21 Jul 2003 at 12:45 PM
This message was edited by lillu at 2003-7-21 12:47:39

Hi,

Please forget all the code I sent so far... they're rubbish just a produce of my unreliable memory.

I decided to sit down and write this script or these errors I may have put in the previous code just gonna haunt me forever.

I tested so it works:

I changed the output.htm and output framename to output1 as I have a feeling that I managed to bump into some reserved words though I'm not sure.

Now the script waits until output1 is loaded then it sets is variable to true and sends it to its parent when it fires so we know that the output1 has surely loaded, then we get notified that the whole frameset is loaded:

1. frameset page

<html>
<head>
<script language="javascript">
var loaded = false;
if (document.loaded == "undefined")
{
alert('Output1 not yet loaded');
}
else
{
alert('Output1 loaded');
}
</script>
</head>
<frameset cols="*,100%" onLoad="javascript:alert('Frames loaded');">
<frame src="process1.htm" name="process1">
<frame src="output1.htm" name="output1">
</frameset>

2. output1 page (where you output the results from the process1 calculations)

<html>
<head>
<script language="javascript">
function passValue()
{
parent.document.loaded = true;
}
</script>
</head>
<body onload="passValue();">
</body>
</html>

3. process1 (contains no script)

<html>
<head></head>
<body>
</body>
</html>

You see this is where I got when I try to code by ear hahaha...

Good luck,

Lillu





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.