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
ebenrouxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

archrajanCommented:
please post the code
0
ebenrouxAuthor Commented:
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
0
archrajanCommented:
you can insert the script at the head of the document

do u have anyscript that runs onload?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

EsopoCommented:
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.
0
ebenrouxAuthor Commented:
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
0
archrajanCommented:
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
0
ebenrouxAuthor Commented:
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
0
archrajanCommented:
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>
0
ebenrouxAuthor Commented:
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
0
EsopoCommented:
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.
0
alexmayCommented:
I have a similar problem which I seemed to be able to work around by loading the page with the iframe empty (src="").
Then I could start the script that I wanted running and then do a iframe.src="realsourche.html" type of command
to put the real source in the iframe.
Maybe that would work for you too.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ebenrouxAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.