<?php
if (@$_GET['wait']) {
    sleep(2);
    echo 'true;';
    exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>setTimeout DOMReady Test</title>
    <style type="text/css" media="screen">
    <!--
        BODY { margin: 10px; padding: 0; font: 1em "Trebuchet MS", verdana, arial, sans-serif; font-size: 100%; }
        H1 { margin-bottom: 2px; }
        DIV.container { margin: auto; width: 90%; margin-bottom: 10px;}
        TEXTAREA { width: 80%;}
        FIELDSET { border: 1px solid #ccc; padding: 1em; margin: 0; }
        LEGEND { color: #ccc; font-size: 120%; }
        INPUT, TEXTAREA { font-family: Arial, verdana; font-size: 125%; padding: 7px; border: 1px solid #999; }
        LABEL { display: block; margin-top: 10px; } 
        IMG { margin: 5px; }
    -->
    </style>

    <script type="text/javascript" src="/js/jquery.js"></script>
    

    <script type="text/javascript">
    <!--
    function DOMReady(f){
      if (/(?!.*?compatible|.*?webkit)^mozilla|opera/i.test(navigator.userAgent)){ // Feeling dirty yet?
        document.addEventListener("DOMContentLoaded", f, false);
      }else{
        window.setTimeout(f,0);
      }
    }
    
    function test(via) {
        try {
            document.getElementById('debug').innerHTML += '<p>Ready via ' + via + '</p>';
        } catch (e) {
            alert('failed');
        }
    }
    
    DOMReady(function () { test("setTimeout"); });
    $(function () { test("jQuery ready"); });
    
    
    //-->
    </script>
</head>
<body id="page">
    <h1>setTimeout DOMReady Test</h1>
    <p>This page loads an &lt;script src="" /&gt; tag to itself which waits for 5 seconds before responding.  This is a simple simulation of a slow response from, for example, external ads served through JavaScript (or perhaps an iFrame - though not tested).</p>
    <p>We are expecting to see <strong>two</strong> 'ready' statements.  An alert box will show if DOM wasn't ready when the code tried to run.</p>
    <p>Firefox will show the two ready statements.  IE7 and Safari will show a failure and only one of the ready statements (executed using jQuery).</p>
    <script src="onload.php?wait=true" type="text/javascript" charset="utf-8"></script>
    <div id="debug"></div>
</body>
</html>





