javascriptjqueryiframedetectionopenx

Jquery/javascript detection if iframe can be loaded


I have iframes with OpenX ads I server from another server/domain.

When something happens to this ad server the main server doesn't load whole contents because the domain that openx loads in iframe is not responding. I always thought that iframe works independently from the main site but it doesn't if the domain doesn't answer at all...

Anyway can main site detect somehow that a url in iframe is not responding and skips loading iframe and show the rest of the site?


Solution

  • How about loading the iFrame once the website is loaded? It's pretty easy to do this using jQuery (or even plain javascript using the window.load event).

    So rather than wanting to 'detect' whether the iFrame has loaded, you can load it AFTER the rest of the website has completed loading. (sorry for excessive use of word 'load')

    In jQuery, you can simply attach the url to the iFrame on the document.ready event.

    A blank iFrame

    <iframe id="iframe-ad" width="200"></iframe>
    

    Simple jQuery to load the URL on document.ready

    <script type="text/javascript">
        $(document).ready(function() {
            $("#iframe-ad").attr("src", "http://www.google.com");
        });
    </script>