I have made a simple popup image viewer. You can see a demo page for it here:
http://caerphoto.com/quickslide/and the actual JS here:
http://caerphoto.com/quickslide/quickslide.jsI am trying to add a useful error handler to the image object created in the setPopup()
function (line 169 or so), but it's proving difficult. Registering the handler works fine, and when something goes wrong, the handler fires.
The problem is, unimportant things like 'wrong MIME type' count as errors, at least on Windows (seems fine in OS X, in Chrome and FF4), so the error message pops up every time even though the image loaded just fine.
Is there some way to determine what the actual error was, s开发者_运维技巧o I can filter out the important ones (e.g. 404s) and respond accordingly? To clarify, I'm asking about handling an error event, not a JavaScript exception.
I've tried inspecting the error object passed to the handler, but it doesn't appear to contain any useful information.
edit:
It appears I was mistaken about the cause of the error – it turns out that this line was causing it:
popupImg.src = "";
The question is still stands, however – it'd be useful to know exactly what went wrong.
Have you looked at the error object in a Mozilla browser? You can always wrap things in try...catch
(docs) blocks to see your exception details, which provides quite a bit of information.
try {
var t = a.notexists + b.thisisnotreal;
} catch (e) {
/* do something with the error */
}
The error object has limited utility with IE, you get some non-standard stuff but it isn't really doing you any favors. With Mozilla, there are some non-standard properties worth mentioning, specifically stack
and lineNumber
- most useful for debugging.
精彩评论