Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Proper handling of invalid frame/form

Posted on 2000-03-02
13
Medium Priority
?
266 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
[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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 800 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
 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
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…

618 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