dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to detect if an iframe/frame has loaded the document ?

  1. #1
    Join Date
    Nov 2004
    Posts
    12

    How to detect if an iframe/frame has loaded the document ?

    I have a web page containing an IFRAME. After a certain period of time I have
    to change the IFRAME src property. This action can fail for a lot of reasons (e.g. a network problem ). In such a case I would like to show another page - which is
    on the client machine - in the iframe.

    So far I was unable to do that because I don't know how to detect if the IFRAME
    loading succeeded. Is there any way to see if the operation succeeded ?

    thanks.

  2. #2
    Join Date
    Jun 2003
    Location
    Sydney
    Posts
    109

    Re: How to detect if an iframe/frame has loaded the document ?

    To my knowledge IFRAME's work like a normal browser, so if a page doesnt load it would be the same as if it didnt load in a normal browser window, you would get the standard page cannot be displayed message.

    Some questions though, what page are you going to load on client machine if it fails and how do you know it will be there? This sort of goes against scripting protocol.

    Here is my untested theory of what you can do to test if page has loaded. A big stress that this is untested and probably unlogical.

    1. Use a javascript function to load the IFRAME.
    2. In the IFRAME code have a hidden tag at the end of the page marked LOADED as this is at the end of the page you will be sure it is loaded,
    3. From the main page check for a certain number of seconds if the IFRAME is loaded tag is there
    4. After you have expired time, then redirect the frame to your client page.

    This is my 30 second solution with no research, but it might help you.
    </VANNY>

  3. #3
    Join Date
    Nov 2004
    Posts
    12

    Re: How to detect if an iframe/frame has loaded the document ?

    >
    > Some questions though, what page are you going to load on client machine
    > if it fails and how do you know it will be there?
    >

    It is very simple : It can be sad that I have administrative rights on the client
    machine. So, you can imagine that the application we create is not available
    to all the internet. It is an application used inside and organization.

    Ok... now about your solution. It sounds very nice, but there is a problem. The page I create (the page loading the IFRAMEs) is not on the same site as the
    page for which I want to check for loading errors, so I cannot script its contents.

    By the way : Are there any elements which can be inter-FRAME scripted even if
    the pages do not belog to the same suffix domain ?

    Cristi

  4. #4
    Join Date
    Jan 2006
    Posts
    1

    Talking Re: How to detect if an iframe/frame has loaded the document ?

    Maybe this is your answer?..
    Code:
    <html>
    <head>
    
    <script language="javascript">
    <!--
    
    function ensureInFrameset()
    	{
    	var parentFramesetLocation = "http://localhost/framereloader/frame1.asp";
    	var reg = new RegExp(parentFramesetLocation,"i");
    	if ((parent.location.href + "").search(reg) < 0)
    		window.open(parentFramesetLocation,"_parent");
    	}
    
    ensureInFrameset();
    
    //-->
    </script>
    
    </head>
    <body>
    
    content for file
    
    </body>
    </html>
    "here's a simple example. it checks that the parent frame has the expected url and reloads the page into the parent frame if it doesn't."

    Source

  5. #5
    Join Date
    Dec 2003
    Location
    Gods own country, India
    Posts
    248

    Re: How to detect if an iframe/frame has loaded the document ?

    this is my way...
    ur using javascript
    just before loading hide the iframe , and in the loaded page the last thing shld be a javascript snippet which calls the parent document's custom javascript function say rst() , which reenables the iframe, u can also start a timer and a flag variable along with the above stated for timeout redirections etc..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)