By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,317 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,317 IT Pros & Developers. It's quick & easy.

Catching 404 and 500 in IFRAMEs?

P: n/a
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/...n_onerror.html >
[2] <URL:http://groups.google.com/groups?hl=n...8%26oe%3Dutf-8 >
[3] <URL:http://groups.google.com/groups?hl=n...8%26oe%3Dutf-8 >
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Steinar Bang wrote:
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.

[snip]

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

<URL:http://archives.real-time.com/pipermail/tomcat-devel/2000-January/003482.html>

--
Jim Dabell

Jul 20 '05 #2

P: n/a
Steinar Bang wrote:
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.
--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #3

P: n/a
>>>>> Jim Dabell <ji********@jimdabell.com>:
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...?
Jul 20 '05 #4

P: n/a
>>>>> Klaus Johannes Rusch <Kl********@atmedia.net>:
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
Jul 20 '05 #5

P: n/a
In article <87************@home.lan>, sb@dod.no enlightened us with...

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
-------------------------------------------------
Jul 20 '05 #6

P: n/a
>>>>> kaeli <in********************@NOSPAMatt.net>:
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?
Jul 20 '05 #7

P: n/a
In article <87************@home.lan>, sb@dod.no enlightened us with...
>> kaeli <in********************@NOSPAMatt.net>:

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?


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
-------------------------------------------------
Jul 20 '05 #8

P: n/a
>>>>> kaeli <in********************@NOSPAMatt.net>:
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
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.