Solved

Proper handling of invalid frame/form

Posted on 2000-03-02
13
232 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>

0
Comment
Question by:rakhras
  • 7
  • 3
  • 2
  • +1
13 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 2577477
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
 

Author Comment

by:rakhras
ID: 2577745
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 2577937
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
 

Author Comment

by:rakhras
ID: 2578364
Thanks for the feedback. It's not actually the case. Both pages are located on the same local server.
0
 

Author Comment

by:rakhras
ID: 2580696
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
 
LVL 9

Accepted Solution

by:
TTom earned 200 total points
ID: 2584166
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rakhras
ID: 2585263
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
 
LVL 9

Expert Comment

by:TTom
ID: 2587715
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
 

Author Comment

by:rakhras
ID: 2587806
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
 

Author Comment

by:rakhras
ID: 2588504
Adjusted points to 200
0
 

Expert Comment

by:summersda
ID: 2588969
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
 

Author Comment

by:rakhras
ID: 2589409
summersda,

you are right. Tom's answer is correct.


Tom,

My sincere apologies.
Your solution works.

Thanks again,
Ralph
0
 
LVL 9

Expert Comment

by:TTom
ID: 2589422
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

707 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

15 Experts available now in Live!

Get 1:1 Help Now