Catching 404 and 500 in IFRAMEs?

S

Steinar Bang

Is there a way to catch HTTP 4xx and 5xx errors occuring in an IFRAME?
I want to replace the blue and white tomcat error pages, with a small
discrete text saying "The page currently not available".

The browser in question is Mozilla 1.3.1. But it would be nice if the
solution also worked in Opera 7.x, and IE 5.x and 6.x.

I know that setting an onError function on the IFRAME doesn't work,
both because [1] says that it only works for JavaScript errors and not
for browser errors, and because I've tried it.

Searches on http://groups.google.com found me two threads about this
problem ([2], [3]), but no solutions that I could see.

One approach I could think about, is to set an onLoad function on the
frame, and check the load status code. Is the load status code
available on the frame? (One future problem here, is that I've heard
rumours about Opera having problems with onLoad)

Are there other possible solutions?

Thanx!


- Steinar


References:
[1] <URL:http://www.devguru.com/Technologies/ecmascript/quickref/evhan_onerror.html >
[2] <URL:http://groups.google.com/groups?hl=...+error&sourceid=opera&num=0&ie=utf-8&oe=utf-8 >
[3] <URL:http://groups.google.com/groups?hl=...+error&sourceid=opera&num=0&ie=utf-8&oe=utf-8 >
 
K

Klaus Johannes Rusch

Steinar said:
Is there a way to catch HTTP 4xx and 5xx errors occuring in an IFRAME?
I want to replace the blue and white tomcat error pages, with a small
discrete text saying "The page currently not available".

The browser in question is Mozilla 1.3.1. But it would be nice if the
solution also worked in Opera 7.x, and IE 5.x and 6.x.

I know that setting an onError function on the IFRAME doesn't work,
both because [1] says that it only works for JavaScript errors and not
for browser errors, and because I've tried it.

Searches on http://groups.google.com found me two threads about this
problem ([2], [3]), but no solutions that I could see.

One approach I could think about, is to set an onLoad function on the
frame, and check the load status code. Is the load status code
available on the frame? (One future problem here, is that I've heard
rumours about Opera having problems with onLoad)

Are there other possible solutions?

As long as the iframe is in the same domain, you should be able to access its contents and if you identify a Tomcat error, either overwrite the content or make the iframe invisible by applying a different style. A better solution would be error
handling on the Tomcat server, though, or accessing Tomcat through an application that interprets the response from Tomcat and replaces it with a friendly message in case of failures.
 
S

Steinar Bang

Jim Dabell said:
Don't do this with client-side code. Just configure your server
appropriately.

The application in question is a framework where custom pages can be
shown inside IFRAMEs, based on settings in the database.

I already do the server side stuff, with ErrorDocument directives
setting friendlier pages in apache's httpd.conf, and <error-page>
elements doing the same thing for tomcat in the webapp's web.xml file.

But I would have liked to let the JSP framwork on the to document
handle the case for errors happening on a separate server, displaying
in the IFRAMEs.

Looks like this isn't possible. Strange that the numerical HTTP
result code isn't available on the document objects...?
 
S

Steinar Bang

Klaus Johannes Rusch said:
As long as the iframe is in the same domain, you should be able to
access its contents

It's not possible for JavaScript code in the top document to access
IFRAME content loaded from a different server, is that what you're
saying?
and if you identify a Tomcat error, either overwrite the content or
make the iframe invisible by applying a different style.

You mean parse the document to find out? I had been hoping to be able
to check the numerical HTTP result code for the document, but no such
luck.

Really strange that it isn't available. It seems such a simple thing
to implement, and simple thing to test against for error situations.
A better solution would be error handling on the Tomcat server,
though, or accessing Tomcat through an application that interprets
the response from Tomcat and replaces it with a friendly message in
case of failures.

Yup. I already do that for the server serving out the top document
(and the one most likely to serve out the other documents as well).

But like I said in another posting, I was hoping to have the JSP
framework in the top document being able to handle errors occuring on
a separate server, displaying inside one of the IFRAMEs.


- Steinar
 
K

kaeli

But I would have liked to let the JSP framwork on the to document
handle the case for errors happening on a separate server, displaying
in the IFRAMEs.

Sure you can. Just check the document for existence before it is loaded
in the iframe with java's url class. After you verify it, then load it.
See comp.lang.java* groups.


-------------------------------------------------
~kaeli~
Hey, if you got it flaunt it! If you don't, stare
at someone who does. Just don't lick the TV screen,
it leaves streaks.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
S

Steinar Bang

kaeli said:
Sure you can. Just check the document for existence before it is
loaded in the iframe with java's url class. After you verify it,
then load it. See comp.lang.java* groups.

Is this something that requires a Java applet in the browser?
 
K

kaeli

Is this something that requires a Java applet in the browser?

No, you mentioned you use JSP. Use that.

Whatever opens the doc in the IFRAME must run on the server and check
the location before loading.
For example, if you load the iframe by a user clicking a link, set all
your links to one document (say, checkIt.jsp?
page=http://server.com/whatever.html) and send the url they want to load
as a parameter. Have checkIt.jsp check that location. If it exists,
change location to that page, if not display error. The same can be done
with button clicks, etc.

-------------------------------------------------
~kaeli~
Hey, if you got it flaunt it! If you don't, stare
at someone who does. Just don't lick the TV screen,
it leaves streaks.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
 
S

Steinar Bang

kaeli said:
Whatever opens the doc in the IFRAME must run on the server and
check the location before loading. For example, if you load the
iframe by a user clicking a link, set all your links to one document
(say, checkIt.jsp? page=http://server.com/whatever.html)

I do all loading of the IFRAME through a Struts action, so I could
actually do it a bit more cleanly than this. I could add the checking
to the action.
and send the url they want to load as a parameter. Have checkIt.jsp
check that location. If it exists, change location to that page, if
not display error. The same can be done with button clicks, etc.

OK, that's an idea.

But it would require an HTTP access from the JSP container to the
source that is to be loaded inside the IFRAME. And that's too costly
in terms of response time, I think.

But thanx for the tip.


- Steinar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,206
Latest member
SybilSchil

Latest Threads

Top