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.

tybro0103
  • 48,327
  • 33
  • 144
  • 170

1 Answers1

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.

Community
  • 1
  • 1
machineghost
  • 33,529
  • 30
  • 159
  • 234
  • 1
    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. – tybro0103 Oct 07 '11 at 20:50
  • 3
    Can you be more descriptive; what exactly did you try, and did it just do nothing, did it get an error, ...? – machineghost Oct 07 '11 at 20:57
  • 2
    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. – machineghost Oct 10 '11 at 18:31
  • Your answer is not valid at all. You told me to do exactly what I'm already trying to do, without any code. I did realize I should add a little clarity to my question. I downvoted you, because I want you to delete your answer so that my question will be marked as unanswered. Thus, I will be more likely to get real answers. Don't get emotional about it. The downvote feature is there for a reason. – tybro0103 Oct 11 '11 at 18:03
  • 1
    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 – machineghost Oct 11 '11 at 19:08
  • 1
    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. – machineghost Oct 11 '11 at 19:10
  • We're all developers here... mentioning that there's an onerror event is not help. What you posted is not an answer, but more of a best guess, as is does not even seem possible to use an iframe's onerror event. Post some code to do so and I will upvote. That would be an answer. Plus, the question provides plenty of info. – tybro0103 Oct 11 '11 at 20:48
  • Honestly Dude, just delete your "answer" until you find some code that is actually an answer. – tybro0103 Oct 11 '11 at 20:50
  • One can see from my other questions that people who give me actual answers are justly rewarded. – tybro0103 Oct 11 '11 at 20:50
  • 1
    "the question provides plenty of info" ... the question says NOTHING about your actual problem; the most info you've given is in the comments: "That's exactly what I'm trying to do. So far doesn't seem to work". That doesn't help anyone. What browser are you using? What happens when you set up an onerror event handler: does it get hit or skipped? If it gets hit, presumably you still see errors anyway? Are all errors appearing after you add a handler, or just the onload ones? If "We're all developers here", "we" should know that "doesn't seem to work" isn't enough info to debug a problem. – machineghost Oct 11 '11 at 22:37
  • Perhaps when I feel up to it I'll post some of the code I've tried already, but I'm not going to change my mind. – tybro0103 Oct 11 '11 at 23:50