Solved

Using onload with a frameset

Posted on 1998-08-25
5
1,043 Views
Last Modified: 2013-11-19
I'm using a frameset tag with an "onload" and the function name in the onload is not being called until I load that page for the second time.

In this example I have a page with multiple frames, within one of those frames I'm loading a new page which has the frameset tag and the onload that I'm having problems with.  This new page (tree.html) is adding two more frames within an existing frame.

The frameset in the top most page looks something like the following (the onload=loadWin() in this page works fine, and is located in the lib.js file):

-----------------------------------------------------------

<SCRIPT LANGUAGE="javascript" SRC="../../../js/lib.js"></SCRIPT>

 
<frameset border=1 frameborder=0 framespacing=0 onLoad=loadWin() cols="22,*,428">

  <frame noresize scrolling="no" src="../../../js/blank.html" name="strip">
  <frame noresize scrolling="no" src="../../../js/blank.html" name="popwin">

  <frameset border=1 frameborder=0 framespacing=0 rows="60,*">
    <frame noresize scrolling="no" src="../../../js/blank.html" name="nav">
    <frame noresize scrolling="auto" framespacing=0 src="../../../js/blank.html" name="main">
  </frameset>

</frameset>

-----------------------------------------------------------

The file that's giving me all the trouble is being loaded in the second frame with the following script.

      window.popwin.document.location="../tree.html";

the tree.html file looks like the following:

-----------------------------------------------------------
<HTML>
<HEAD>

    <SCRIPT language="JavaScript" src="info.js"></SCRIPT>
    <SCRIPT language="JavaScript" src="proc.js"></SCRIPT>
    <SCRIPT  language="JavaScript" src="../../js/browser.js"> </SCRIPT>

    <frameset border=1 frameborder=0 framespacing=0 onload="createBrowser('Draft')" rows="45,*">
      <frame noresize scrolling="no" src="../../js/blank.html" name="poptp">
      <frame noresize scrolling="auto" framespacing=0 src="../../js/blank.html" name="popmain">

    </frameset>

  </HEAD>
</HTML>
-----------------------------------------------------------

Now, my problem is that the createBrowser() function (located in the browser.js file) is not executed until that page (tree.html) is loaded for the second time.  There is a HREF tag in one of the other frames that I'm using to load the popwin frame with the new page.  I understand that I could load the tree.html file when I create the frameset but I only want to load that page if the user makes a selection.

So, my question is, why is the script acting this way and what can I do to make sure the onload will work correctly the first time the page is loaded.

thanks,

Vanfleet
0
Comment
Question by:vanfleet
  • 4
5 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 200 total points
ID: 1269640
Solution 1: Do not put the onLoad scripts in the js file - it loads in whatever order, totally uncontrollably and is not covered by the onLoad which can trigger long before the js file(s) is(are) loaded.

Solution 2. Set a flag to false outside the js file and to true in the bottom of the js file and don't attempt to use any scripts until this flag is true.

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1269641
PS: The reason it works the second time is that the js file has been cached by then

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1269642
PPS: A bug in Netscape 3.x will trigger the onLoad before all pages have been loaded - another reason to use flags if your script are dependant on pages having been loaded or not.

Michel
0
 

Author Comment

by:vanfleet
ID: 1269643
When I put the function called in the onload in the same file (outside of the js file) it seems to work fine.  I should note here that I had to put the function at the top of the page before the script tags with the js files.  If I put the function after the other script tags I had the exact same result as before.  I'm not sure why, that page has got to be entirly loaded by then.

Thanks for your help,
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1269644
I have noticed that especially Netscape 4 tries to be 'clever' and 'nice' to you and tries to load as much as possible in as clever a way it can - I would not be surprised that if Netscape suspects that the .js file might contain something useful, it will delay execution of other things.

I have a problem with a polling script that tries to load one image from several servers. The property image.complete should be set be either onLoad/onError or onAbort but netscape 4 says, oh, what the heck, let's set it immediately we have tried accessing the image instead of when one of the above events happened. This is not the only time I have seen this kind of behavior.

The really big problem is when they fix it in the next version and your script might not work anymore because you were relying on a 'bug'...

Happy to hear you solved your problem.

Dooi,

Michel


0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now