简体   繁体   English

Javascript! IE文件准备好state

[英]Javascript! IE document ready state

Im not big javascript guru so i would be glad if someone could help me with this.我不是大 javascript 大师,所以如果有人可以帮助我,我会很高兴。 Ok so what i wish to do is to display simple indicator for file download while files will prepared.好的,所以我想做的是在准备文件时显示文件下载的简单指示器。 Now everything works perfectly in Firefox but not in IE loader will be created by php and download comes through iframe.现在一切都在 Firefox 中完美运行,但不是在 IE 加载器中将由 php 创建,下载来自 iframe。 Now as you can see from code below i checked for document ready state and for some reason it stays interactive for IE and never completes but in Firefox in completes nicely.现在正如您从下面的代码中看到的那样,我检查了准备好的文档 state 并且由于某种原因它对 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>';
}

I really liked solution for removing indicator like this cause in firefox it removes indicator right after save file dialog is displayed but in IE it dosen't just work.我真的很喜欢在 firefox 中删除此类指示器的解决方案,它会在显示保存文件对话框后立即删除指示器,但在 IE 中它不仅可以工作。

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

Anny suggestions?有什么建议吗?

Ok heres script which works in IE and in Firefox.好的,适用于 IE 和 Firefox 的脚本。 Basically i need to check iframes ready state which turns "NaN" in Firefox and firstly to "loading" in IE and to "interactive" on complete(IE) So i create startingState with value "loading" to work it in both browser cause IE changes it's state twice and Firefox only once.基本上我需要检查 iframe 准备好 state ,它在 Firefox 中变成“NaN”,首先在 IE 中“加载”并在完成时“交互”(IE)所以我创建了值为“正在加载”的startingState,以便在两个浏览器中工作它导致 IE将其 state 更改两次,Firefox 仅更改一次。 In Chrome and Opera iframe ready state turns to "undefined" and will do it only once so if anyone has fix for that it would be also great.在 Chrome 和 Opera 中 iframe 准备好 state 变成“未定义”并且只会执行一次,所以如果有人修复它也会很棒。

<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>';

UPDATE:更新:

Use messaging - MSDN - MDN - to safely communicate cross domain/crossframes from a page on your server to another page on another of your servers使用消息传递 - MSDN - MDN - 将跨域/跨框架从您服务器上的一个页面安全地通信到另一个服务器上的另一个页面

How about this这个怎么样

<?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 } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM