1

I have a site in which I take great pride in the fact that no javascript errors happen. New requirements make me have to put an iframe on my site which displays someone else's site of a different domain, and I have no access to their code. Their javascript consistently throws errors which causes users to see an ugly red x in the bottom of their browser.

Is it possible to handle that error on my end and disregard it?

Update:
In short, I'm trying to find a way to hijack the iframe's window.onerror handler.

Update:
I don't believe there is an answer here. Even if I could hijack the iframe onerror events, I don't think there's a way to make the ugly red 'X' go away. I'll leave the question here in hopes that I'm wrong.

2
  • Does the other site have some JSON way of getting data? Commented Oct 7, 2011 at 19:23
  • @Detect I'm not sure what exactly you're asking, but I don't have any way to communicate with the site or have any control over it. Commented Oct 7, 2011 at 19:28

1 Answer 1

5

What you're basically asking (I think) is "can I put a try/catch around the IFRAME's code", and the answer is no. However, you can come close, in many browsers at least (not Opera) by using window.onerror (and since the IFRAME has it's own window, you should be able to use this technique to capture only the IFRAME's errors).

See: Javascript global error handling for further info.

Sign up to request clarification or add additional context in comments.

11 Comments

That's exactly what I'm trying to do. So far doesn't seem to work, and I can't find anyone else who has done it.
Can you be more descriptive; what exactly did you try, and did it just do nothing, did it get an error, ...?
So I give you a perfectly valid answer (to your original, un-edited question), and in return you vote that answer down and edit your question in to a different one. And then when I ask for you to clarify matters so that I can answer your new question, you don't even have the courtesy to respond. Classy.
A) it was valid for your original question, which made no mention of onerror whatsoever and just said "how do I do this"; I answered that, B) you don't need to downvote an answer if has 0 votes; your question will still count as unanswered C) the downvote is designed for when someone gives a bad answer; my answer was a perfectly good answer until you changed the question (and it's still the best answer, because ...) D) your question has been "unanswered" for three days and no one else has responded ... maybe because they don't want to be penalized for trying to help you like I was
E) I'm not being "emotional", I'm calling you out for asking for help, down-voting me when I tried to help you (by answering the question you asked), and (STILL) not providing any further info so that I (or anyone else) can actually give a valid answer to your new question.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.