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
Add a ment  | 

1 Answer 1

Reset to default 6

The 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