We help IT Professionals succeed at work.

Proper handling of invalid frame/form

rakhras
rakhras asked
on
288 Views
Last Modified: 2010-04-09
Hi,

I have a frameset that contains 2 frames. Under some circumstances, one of the frame (say FRAME2) is not loaded properly.

However, the frame that is loaded (FRAME1) make references to FRAME2.

This results in an error message.

I would like to try to detect if FRAME2 was properly loaded before making any reference to it.

I included a sample test below.
Save FRAMESET.HTM in a file.
Save FRAME1.HTM in a file.

Load FRAMESET.HTM in IE.
The middle frame will fail to load.
Click on the SetCursor button.
An error dialog will popup because FRAME2 does not exist. I want to be able to properly handle this error.

Any ideas?
Thanks,
Ralph



// FRAMESET.HTM //
<HTML>
<HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">

</HEAD>

<FRAMESET framespacing=1 border=0 frameborder=0  ROWS="30%,30%,*">

    <FRAME  
    SRC="FRAME1.htm"
    NAME="FRAME1"
    FRAMEBORDER=0
    SCROLLING=auto
    ALIGN=top
    MARGINWIDTH=1
    >

    <FRAME
    SRC="FRAME2.htm"
    NAME="FRAME2"
    FRAMEBORDER=0
    SCROLLING=auto
    ALIGN=top
    MARGINWIDTH=1
    >
   
    <FRAME
    SRC="FRAME1.htm"
    NAME="FRAME3"
    FRAMEBORDER=0
    SCROLLING=auto
    ALIGN=top
    MARGINWIDTH=1
    >
   
   
</FRAMESET>

</HTML>



// FRAME1.HTM //
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>


<SCRIPT language=javascript>

      function SetCursor()            
      {
            parent.FRAME1.document.all("FRAME1").style.cursor = "hand";
            parent.FRAME2.document.all("FRAME2").style.cursor = "hand";
      }

</Script>

<BODY>

<FORM Name=Frame1>

<P>&nbsp;</P>

THIS IS FRAME1

<P>&nbsp;</P>

<INPUT TYPE=BUTTON VALUE=SetCursor onClick='SetCursor()'>

</FORM>
</BODY>
</HTML>

Comment
Watch Question

CERTIFIED EXPERT

Commented:
Try this:

function SetCursor()
{
   parent.FRAME1.document.all("FRAME1").style.cursor = "hand";
   if ( parent.FRAME2 )
    if ( parent.FRAME2.document )
     if ( parent.FRAME2.document.all )
      if ( parent.FRAME2.document.all("FRAME2") )
       parent.FRAME2.document.all("FRAME2").style.cursor = "hand";
}

Author

Commented:
Your suggestion works fine in the sample I included.
It does not work in my actual application where I get an "Access denied" message when referencing parent.FRAME2.document.

I'm trying to find out what the difference is.
CERTIFIED EXPERT

Commented:
If the page in your second frame is not on your domain, then you cannot access the document.  For example, on your site, if you open a top frame with a page from your server (www.yourdomain.com) , and a bottom frame with a page from a different server (www.nfl.com), you cannot change the cursor on the bottom frame because the page does not reside on your domain.  The Access Denied message is a built-in security feature to indicate this.

Author

Commented:
Thanks for the feedback. It's not actually the case. Both pages are located on the same local server.

Author

Commented:
It seems that there is a difference on how you access the file.

If I load the HTML page as a file (not via a web server), then your solution is fine.

If I load the HTML page via a web server (even if the web server is local), then I get an "Access denied" error.

Of course, the real life situation is the latter.

Any other ideas?
Thanks,
Ralph
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for your suggestion Tom.

I do not see how your solution addresses the problem.

Please review the problem as stated above.

Thank you,
Ralph

Commented:
I thought the problem which you stated is that an error occurs if you try to reference a frame which is not completely (or properly) loaded (at least that's what I got from the question).

The solution I suggested "flags" the frame in question by changing the value of a particular variable ONLY when that frame is properly loaded.  By testing the value of that variable, you can "short circuit" any code which would result in an error being generated due to the frame not being loaded.

Does that not accomplish what you want?

In addition, I proposed that you could set a timer mechanism to retry your code at a set interval, in case the load is just being slow for some reason.

Have I misunderstood your problem?

Tom

Author

Commented:
Yes, but I need to reference the FRAME2 from FRAME1 and your 'loaded' variable lives in FRAME2, hence I cannot query this variable from FRAME1 ...

I suggest you try the sample I provided.

Author

Commented:
Adjusted points to 200
I was actually looking for an answer to something similar. I have 2 main frames and a 3rd frame which references a <DIV> on a main frame. If I hit refresh and it tries to refresh the whole "page", I too get an error saying it cannot reference the item on the main page. The point being that it sounds like TTom is correct. If Frame2 is not loaded then the value by default would be false. When that frame finally loads then the value will be changed to true. If you check the value in Frame2 from Frame1 and if False (not loaded) then wait and try again. It looks like his answer answered the question asked.

Author

Commented:
summersda,

you are right. Tom's answer is correct.


Tom,

My sincere apologies.
Your solution works.

Thanks again,
Ralph

Commented:
No apology necessary.  Glad to get you functioning the way you want.  (Please feel free to accept appropriate comment as answer.)

Tom

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.