admin管理员组文章数量:1427340
I have a script that inject an Iframe to my page, In rare occasions the service is down and the Iframe content is a 404 page content.
Can I detect somehow that the response of a cross domain page ( in-iframe ) is 404?
I have a script that inject an Iframe to my page, In rare occasions the service is down and the Iframe content is a 404 page content.
Can I detect somehow that the response of a cross domain page ( in-iframe ) is 404?
Share Improve this question asked Jan 19, 2013 at 18:10 gmadargmadar 1,9043 gold badges19 silver badges22 bronze badges 3- Are you sure you're getting a 404? That doesn't really make sense when the service is down – Pekka Commented Jan 19, 2013 at 18:15
- if you are search a way to hide the error page(might be 40x 50x) of iframe, i suggest that you use div to cover it. and then, iframe loaded and your custom script in iframe tigger to remove the cover div. – farmer1992 Commented Jan 19, 2013 at 18:17
- @Pekka웃 you right, it's just not responding it's not a 404. – gmadar Commented Jan 20, 2013 at 13:16
1 Answer
Reset to default 6The simple answer is "no," not without CORS or help on the server side. The whole point of the same-origin policy is that you can't get information about content served from somewhere else.
Try using a server-side script to make a HEAD request to the site in question and make sure it's up.
Another possible workaround: Find an image on their site, and try to load that first. When the image loads, load the iframe. If it fails to load after some period of time, you can assume the server's down, and show a custom "oops" message. May or may not work depending on what's actually going on with that server.
本文标签: javascriptCan I detect that a crossdomain iframe contains a 404 responseStack Overflow
版权声明:本文标题:javascript - Can I detect that a cross-domain iframe contains a 404 response? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745463588a2659432.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论