Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

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>

0
rakhras
Asked:
rakhras
  • 7
  • 3
  • 2
  • +1
1 Solution
 
knightEknightCommented:
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";
}
0
 
rakhrasAuthor 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.
0
 
knightEknightCommented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
rakhrasAuthor Commented:
Thanks for the feedback. It's not actually the case. Both pages are located on the same local server.
0
 
rakhrasAuthor 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
0
 
TTomCommented:
Bit of a kludge, but what you could do in your frameset is define a JS variable, e.g., "loaded=false".  In the source for Frame2, add:

<body onload="javascript:loaded=true;">

Then, in the source for your script, add a test for the variable, e.g.,

if not (loaded == "true") {
   exit gracefully
   } else {
   change my cursors
}

You could extend this by adding code to set a timer to recheck the variable if it fails the first time.

HTH,

Tom
0
 
rakhrasAuthor 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
0
 
TTomCommented:
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
0
 
rakhrasAuthor 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.
0
 
rakhrasAuthor Commented:
Adjusted points to 200
0
 
summersdaCommented:
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.
0
 
rakhrasAuthor Commented:
summersda,

you are right. Tom's answer is correct.


Tom,

My sincere apologies.
Your solution works.

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

Tom

0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 7
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now