Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  174] [ 1]  / answers: 1 / hits: 75530  / 11 Years ago, sat, may 11, 2013, 12:00:00

My Web page uses iframes to collect content from other pages. All pages are in the same domain.



From the main page, is there a way to confirm that all iframes have loaded, and that there is no 404 error?


More From » iframe

 Answers
7

The status only lives in the response header.



The 404 Page is handling an HTTP Status Code, which is only included in the server's response sent to the browser, but not in the actual window and document objects of the DOM that javascript may access. This means that while you certainly can collect the status-code and take appropriate actions, you may only do so when your javascript is receiving the response, such as with a jQuery.ajax() request or an XmlHttRequest to load your iframe.



Hope the 404 page follows 404 standards.



If the above isn't an option, the only other possibility may be to check the title, and/or H tags, for 404 . While this is most certainly less than ideal (I'd love to see, 404, Movie not Found, the Movie.), it is your only other option.



$('#iframe').load(function (e) {
var iframe = $(#iframe)[0];

if ( iframe.innerHTML() ) {
// get and check the Title (and H tags if you want)
var ifTitle = iframe.contentDocument.title;
if ( ifTitle.indexOf(404)>=0 ) {
// we have a winner! probably a 404 page!
}
} else {
// didn't load
}
});

[#78292] Thursday, May 9, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
katieh

Total Points: 692
Total Questions: 104
Total Answers: 104

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;