Catch a 404 when using an iFrame

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • plex4r

    #1

    Catch a 404 when using an iFrame

    I am using iFrames to integrate two systems at the HTML level.
    If the included content in an iFrame is not available, how can I detect
    this in the outer page in JavaScript?

    Thanks, plex4r

  • Martin Honnen

    #2
    Re: Catch a 404 when using an iFrame



    plex4r wrote:
    [color=blue]
    > I am using iFrames to integrate two systems at the HTML level.
    > If the included content in an iFrame is not available, how can I detect
    > this in the outer page in JavaScript?[/color]

    The frame will display the answer from the server and there are no
    objects or properties on window or document to find out the HTTP
    response status that resulted in the document sent.

    If you know what kind of 404 error document that server sends you could
    check the title perhaps e.g.
    var frameDoc = window.frames.i frameName.docum ent;
    if (frameDoc.title == 'title the server sends for 404') {

    Besides that you could make a HTTP HEAD request for the frame URL with
    XMLHttpRequest in browsers that support that. There you can check the
    HTTP response status code.

    Both approaches work only if the container document and the frame
    document are served from the same server.



    --

    Martin Honnen
    http://JavaScript.FAQTs.com/

    Comment

    Working...