Tay*_*kes 8 html javascript error-handling dom-events
从其他域加载iframe时是否有任何方法可以捕获错误.这是jsfiddle中的一个例子.http://jsfiddle.net/2Udzu/.如果收到错误,我需要显示一条消息.
这是我想做的,但它不起作用
$('iframe')[0].onerror = function(e) {
alert('There was an error loading the iFrame');
}
Run Code Online (Sandbox Code Playgroud)
有人有主意吗?
这onerror仅适用于脚本错误.帧内容错误检查必须使用任何其他方法完成.这是一个例子.
<script>
function chkFrame(fr) {
if (!fr.contentDocument.location) alert('Cross domain');
}
</script>
<iframe src="http://www.google.com/" onload="chkFrame(this)"></iframe>
Run Code Online (Sandbox Code Playgroud)
由于跨域限制,无法检测页面是否成功加载,或者是否由于客户端错误(HTTP 4xx错误)和服务器错误(HTTP 5xx错误)而无法加载页面.
| 归档时间: |
|
| 查看次数: |
5822 次 |
| 最近记录: |