Solved

Using onload with a frameset

Posted on 1998-08-25
5
1,048 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

912 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

26 Experts available now in Live!

Get 1:1 Help Now