最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

How to handle javascript errors inside an iframe? - Stack Overflow

matteradmin4PV0评论

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.

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.

Share Improve this question edited Oct 11, 2011 at 18:06 tybro0103 asked Oct 7, 2011 at 19:19 tybro0103tybro0103 49.8k34 gold badges148 silver badges172 bronze badges 2
  • Does the other site have some JSON way of getting data? – Detect 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 municate with the site or have any control over it. – tybro0103 Commented Oct 7, 2011 at 19:28
Add a ment  | 

1 Answer 1

Reset to default 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 e 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.

Post a comment

comment list (0)

  1. No comments so far