Solved

Frame Checking

Posted on 2001-08-22
4
143 Views
Last Modified: 2012-05-04
Good day.

I have a site with two frames. I have javascript in both frames and occassionally, one frame will run javascript that is in the other frame.

Everything works well except at startup when one frame tries to run javascript that is in the other frame, and that frame has not loaded it yet, then I get a debug error.

So the right frame wants to run the function Test() which is in the left frame. So what I did was write this javascript in the right frame.

function myonload()
{
    myTimer = setTimeout("myonload()",100);
    if (parent.frames.Left.Test())
    {
        clearTimeout(myTimer);
    }
}

which obviously just keeps trying to run Test() until it can and then all is well. This seems to occassionally (particularly in older browsers) to pull an error saying that it could not run

if (parent.frames.Left.Test())

which is obviously because it has not loaded yet. So this seems to be pointless.

Is there a way to test if the frame has loaded yet? I though about playing around with the onload events of each frame but it ends up a vicious circle because the left frame also wants to run javascript in the right frame. I am sure that you will see what I mean when you play with the idea.
0
Comment
Question by:rose337
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 19

Expert Comment

by:webwoman
ID: 6413252
Take out the javascript, put it in a separate file, link to that file. Put the link to the javascript in both documents.

I'm assuming (and could be wrong!) that there's nothing in the script that gets info from either frame in particular. As long as whatever you need is in the script, and not in either frame, it will work fine regardless of whether the other frame is loaded or not.
0
 

Author Comment

by:rose337
ID: 6413282
Unfortunately the javascript that runs in either frame does things to the images and content in that frame, which is why I need to keep the javascript where it is. Thus I do need the frame to load properly. Thanks anyway.
0
 

Author Comment

by:rose337
ID: 6413284
Unfortunately the javascript that runs in either frame does things to the images and content in that frame, which is why I need to keep the javascript where it is. Thus I do need the frame to load properly. Thanks anyway.
0
 
LVL 22

Accepted Solution

by:
CJ_S earned 75 total points
ID: 6413481
function myonload()
{
   if (parent.frames.Left && parent.frames.Left.Test)
   {
       parent.frames.Left.Test()
   }
   else setTimeout("myonload()",100);
}

Regards,
CJ

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

627 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