• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 701
  • Last Modified:

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
0
ebenroux
Asked:
ebenroux
  • 5
  • 4
  • 2
  • +1
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now