Link to home
Start Free TrialLog in
Avatar of ebenroux
ebenroux

asked on

IFrame Load Error causes javascript to stop

Hello Experts!

I have an IFrame that displays text ads from another site.  When this site is unavailable (as is the case during my development) the loading of the IFrame fails as the 'src' arguments points to a non-existent URL.

Now I also have a javascript menu doing it's voodoo to the left of the form, well... not quite.  As soon as the IFrame loading fails it does not run the javascript.

So I need some way to either get the javascript running, or get the IFrame to behave in a better fashion (fail gracefully --- if there really is such a thing).

Regards,
Eben
Avatar of archrajan
archrajan

please post the code
Avatar of ebenroux

ASKER

Hello again,

Actually I had another look.  It appears as though the scripts run AFTER the IFrame has completed loading.  

Is this normal behaviour?

Eben
you can insert the script at the head of the document

do u have anyscript that runs onload?
Hi ebenroux,

About your error page:
If you have server side scripting you can check if the url exists before asking the Iframe to display it. This will allow you to display something else in that space if the URL is not responding.

For example, PHP code:

<?php

if (@fclose(@fopen("http://www.example.com", "r"))) {
     print("File exists.);
} else {
     print("File does not exist.");
}

?>


Best regards,

Esopo.
Hi,

Archrajan: I have tried putting the script all over the place, even the HEAD to no avail.  I have no ONLOAD code either.

Esopo: That is not a bad idea I guess.  I am using .NET, though and am not aware of how to do such a test.

Thanks
Eben
its the nature of javascript to behave that way when the page has some errors..
it normally says object expected error.
try doing a
try
catch
Hey Archrajan,

Now that you mention it it does makes some form of sense, but the IFrame is supposed to be a self-contained little windowed entity.  If this is not the case, how can it be convinced to act as such?

Eben
use try catch see a simple example...
the name of the function is mispelt.. instead o throwing an error it catches it and displays it..
pls post ur code... so tat we cud take a look at whats causing u the error

meanwhile see this example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
   
   <html>
   <head>
   <meta name="Keywords" content="">
   <meta name="Description" content="">
   <meta name="Created" content="">
   <meta name="Last Updated" content="">
   <title>Runtime Error Handling</title>
   <style>
   BODY {
   background-color : #ffffff;
   }
   
   #header {
   color : #000000;
   font : bold 30px Verdana, Geneva,
      Arial, Helvetica, sans-serif;
   }
   </style>
   
   <script language="JavaScript">
   <!--
   var msg = null
   function testHelloWorld()
   {
   try
      {
      heloWorld()
      }
   catch(errorObject)
      {
      msg = "There was an error on this page.\n\n"
      msg += "An internal programming error may keep\n"
      msg += "this page from displaying properly.\n"
      msg += "Click OK to continue.\n\n"
      msg += "Error number: " +
        (errorObject.number & 0xffff) + "\n"
      msg += "Description: " +
        errorObject.description +
        "\n\n"
      alert(msg)
      }
   }
   
   function helloWorld()
   {
   alert("Hello World!")
   }
   //-->
   </script>
   </head>
   
   <body>
   
   <div align="center" id="header">
   Handling Client-side Runtime Errors
   </div>
   
   <p>
   <div align="center">
   <input type="Button"
      name="errorBtn1" value="View Message"
      onclick="testHelloWorld();">
   </div>
   </p>
   
   </body>
   </html>
Ah archrajan,

But you see: all script on the page is 100% correct.  The problem arises when the IFrame loading fails since the 'src' points to a non-existent url.

Eben
Aside from the javascript discussion:

Checking if the URL is valid its very important in your case since you already know it tends to fail. I don't think you want an ugly "page not found" in the middle of your site. I am not a .NET coder but these might help you:

- http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/101476

- http://www.developerfusion.com/show/1605/


Esopo.
ASKER CERTIFIED SOLUTION
Avatar of alexmay
alexmay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Alex,

Actually I found this solution myself today, but since you came up with it have some points.

Apparently this script runs after all the elements on the page has loaded.  This includes images.  Something to bear in mind for the future.  I can just imagine that the load failure causes the rest of the loading on the page to halt.

Regards,
Eben