Javascript!文件准备状态

Javascript!文件准备状态,javascript,window,onload,Javascript,Window,Onload,我不是javascript大师,所以如果有人能帮助我,我会很高兴。 好的,所以我想做的是显示文件下载的简单指示器,同时准备好文件。 现在所有的东西在Firefox中都能很好地工作,但在IE中却不能。loader将由php创建,下载将通过iframe完成。 现在,正如您从下面的代码中看到的,我检查了文档就绪状态,出于某种原因,它在IE中保持交互式,并且从未完成,但在Firefox中完成得很好 if($_POST['download']) { echo '<iframe id="fra

我不是javascript大师,所以如果有人能帮助我,我会很高兴。 好的,所以我想做的是显示文件下载的简单指示器,同时准备好文件。 现在所有的东西在Firefox中都能很好地工作,但在IE中却不能。loader将由php创建,下载将通过iframe完成。 现在,正如您从下面的代码中看到的,我检查了文档就绪状态,出于某种原因,它在IE中保持交互式,并且从未完成,但在Firefox中完成得很好

if($_POST['download'])
{
    echo '<iframe id="frame" src ="download.php?data='.$_POST['download'].'" width="0" height="0" frameborder="0" scrolling="no"></iframe>';

    echo '<div id="loader">';
    echo '<div id="loading-container"><p id="loading-content">Please wait while we prepare your files<img id="loading-graphic" width="220" height="19" src="images/indicator.gif" /></p></div>';
    echo '</div>';
    echo '<script type="text/javascript">

    var wooIntervalId = 0;
    var i = 0;
    function startInterval()
    {
        wooIntervalId = setInterval(doSomething, 1000);
    }

    function doSomething()
    {   
        document.getElementById("loading-content").innerHTML = document.readyState + i;
        i++;
    }

    function remove_elem()
    {
        element = document.getElementById("loader");
        element.parentNode.removeChild(element);
    }

    startInterval();

    </script>';
}
奇怪的建议

好的,这是在IE和Firefox中工作的脚本。 基本上,我需要检查iframes的就绪状态,在Firefox中将“NaN”变为“loading”,在IE中首先变为“loading”,在complete(IE)中变为“interactive” 所以我创建了带有值“loading”的startingState,以便在两种浏览器中都使用它,因为IE将其状态更改了两次,而Firefox只更改了一次。 在Chrome和Opera中,iframe就绪状态变为“未定义”,并且只会执行一次,所以如果有人对此进行了修复,这也将非常好

<script type="text/javascript">
    var startingState = "loading";
    var wooIntervalId = 0;
    function startInterval()
    {
        wooIntervalId = setInterval(doSomething, 1000);
    }

    function doSomething()
    {   
        var doc=document.getElementById("frame");
        if(startingState != doc.readyState)
        {
            remove_elem();
            clearInterval(wooIntervalId);
        }
    }

    function remove_elem()
    {
        element = document.getElementById("loader");
        element.parentNode.removeChild(element);
    }
    startInterval();
    </script>';

var startingState=“加载”;
var-woointervid=0;
函数startInterval()
{
wooIntervalId=设定间隔(剂量计,1000);
}
函数doSomething()
{   
var doc=document.getElementById(“框架”);
if(startingState!=doc.readyState)
{
删除_elem();
清除间隔(有效期);
}
}
函数remove_elem()
{
元素=document.getElementById(“加载器”);
element.parentNode.removeChild(元素);
}
startInterval();
';
更新:

使用消息传递--- 从服务器上的一个页面到另一个服务器上的另一个页面安全地进行跨域/跨帧通信

这个怎么样

<?PHP if (isSet($_POST['download'])) { ?>
  $url = "download.php?data=".htmlentities($_POST['download']);
  <iframe id="frame" src ="<?PHP echo $url; ?>" width="0" height="0" frameborder="0" scrolling="no" onload="remove_elem('loader')"></iframe>
  <div id="loader">;
    <div id="loading-container"><p id="loading-content">Please wait while we prepare your files<img id="loading-graphic" width="220" height="19" src="images/indicator.gif" /></p></div>
  </div>';
  <script type="text/javascript">
    var wooIntervalId = 0;
    var i = 0;
    function startInterval() {
      wooIntervalId = setInterval(doSomething, 1000);
    }

    function doSomething() {   
      document.getElementById("loading-content").innerHTML = document.readyState + i;
      i++;
    }

    function remove_elem(elemId) {
      var element = document.getElementById(elemId);
      element.parentNode.removeChild(element);
    }

    startInterval();

    </script>
<?PHP } ?>

$url=“download.php?data=“.htmlentities($\u POST['download']);

不,现在它在Firefox中不起作用了。好的,还有一点需要注意的是,我可以看到gif图像停止运行,所以指示器不再移动,但它仍在屏幕上(我的版本在IE中)Hm如果我删除iframe,IE将按预期操作,文档准备状态将完成。如果有iframe,IE看起来不会启动。糟糕的是,我不能向iframe添加任何内容来检查它是否已完成,因为它的文件数据直接输出到浏览器,原因是我的数据中心和网站位于不同的服务器中。所以使用消息传递非常好如果我知道iframe是跨域的,我就不会使用onload。请从setInterval(“doSomething()”-有一个隐藏的eval。使用
setInterval(doSomething,1000)
<?PHP if (isSet($_POST['download'])) { ?>
  $url = "download.php?data=".htmlentities($_POST['download']);
  <iframe id="frame" src ="<?PHP echo $url; ?>" width="0" height="0" frameborder="0" scrolling="no" onload="remove_elem('loader')"></iframe>
  <div id="loader">;
    <div id="loading-container"><p id="loading-content">Please wait while we prepare your files<img id="loading-graphic" width="220" height="19" src="images/indicator.gif" /></p></div>
  </div>';
  <script type="text/javascript">
    var wooIntervalId = 0;
    var i = 0;
    function startInterval() {
      wooIntervalId = setInterval(doSomething, 1000);
    }

    function doSomething() {   
      document.getElementById("loading-content").innerHTML = document.readyState + i;
      i++;
    }

    function remove_elem(elemId) {
      var element = document.getElementById(elemId);
      element.parentNode.removeChild(element);
    }

    startInterval();

    </script>
<?PHP } ?>