admin管理员组文章数量:1024603
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.
- 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
1 Answer
Reset to default 5What 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.
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.
- 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
1 Answer
Reset to default 5What 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.
本文标签: How to handle javascript errors inside an iframeStack Overflow
版权声明:本文标题:How to handle javascript errors inside an iframe? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745610073a2158952.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论