Link to home
Start Free TrialLog in
Avatar of rakhras
rakhras

asked on

Proper handling of invalid frame/form

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>

Avatar of knightEknight
knightEknight
Flag of United States of America image

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";
}
Avatar of rakhras
rakhras

ASKER

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.
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.
Avatar of rakhras

ASKER

Thanks for the feedback. It's not actually the case. Both pages are located on the same local server.
Avatar of rakhras

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of TTom
TTom

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rakhras

ASKER

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
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
Avatar of rakhras

ASKER

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.
Avatar of rakhras

ASKER

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.
Avatar of rakhras

ASKER

summersda,

you are right. Tom's answer is correct.


Tom,

My sincere apologies.
Your solution works.

Thanks again,
Ralph
No apology necessary.  Glad to get you functioning the way you want.  (Please feel free to accept appropriate comment as answer.)

Tom