Skip to content Skip to sidebar Skip to footer

Detect If Iframe's Document Is Malformed

I'm loading a page into an IFRAME, and I would like to know if the download was incomplete .. and the HTML is malformed, and missing the closing tags like and

Solution 1:

I'm not sure if you can test for malformed HTML or missing elements without knowing exactly what to expect and testing for it specifically.

If you have access to the source of the iframe page you could call a javascript function variable before the end of the </body> bound to the parent window; (or use the window.onLoad() event to call trigger the call.)

Define this method in your container page.

window.iAmLoaded = function() { 
    alert('iframe loaded OK');
};

Then call it from the iframe;

<scripttype="text/javascript"charset="utf-8">window.parent.iAmLoaded();    
    </script></body>

If this is not an option, and the iframe has a fairly well known DOM, or a distinctive element near the end of the page, you can use getElementById or your favourite library's CSS selector method to locate the element.

Solution 2:

You can use the onLoad event for the iframe to tell when its completed loading. http://www.w3schools.com/jsref/jsref_onload.asp

For detecting malformed html: You're looking for a validator. Browsers don't do that, except, maybe, for xhtml strict. There could well be js validation software.

Larry

Post a Comment for "Detect If Iframe's Document Is Malformed"