【问题标题】:How can I cancel/stop uploading of a file in IE javascript如何在 IE javascript 中取消/停止上传文件
【发布时间】:2011-07-18 14:25:05
【问题描述】:

我有一个包含两个表单的页面。其中之一是不可见的并且包含 input type="file"。我正在使用隐藏表单上传文件(表单的目标是 iframe 元素)。我的问题是如何在 IE 下停止/取消使用 javascript 上传文件。我尝试使用 JQuery 删除隐藏的表单,并且文件仍在上传中。

提前致谢。

【问题讨论】:

  • 尝试移除 iframe,或将 iframe 的位置设置为不同的 url。

标签: javascript upload


【解决方案1】:

好的。我发现这个站点正在寻找相同的东西,但这些解决方案不适用于我的场景。我的表单也有一个 iframe 目标,并想取消上传。这些解决方案由于某种原因不起作用(IE7)。我希望以下内容有所帮助。

问题是从 servlet 发送的指示“文件太大”的响应没有触发目标 iframe onload 事件。

试试:

targetIframe.contentWindow.document.open()
targetIframe.contentWindow.document.close()

这欺骗了 iframe onload 事件触发并自动取消上传。

【讨论】:

    【解决方案2】:

    您可能想要类似于 window.stop() 的东西(应用于 iframe)。

    This old thread 报告说,虽然window.stop() 在 IE 中不起作用,但未记录的 window.document.execCommand("Stop") 可以(至少在 IE5 中)。

    您也可以咨询this StackOverflow page,其答案基本相同,但提出了一些其他技巧。

    【讨论】:

      【解决方案3】:

      感谢您的回复。 就我调试这种情况而言,我得到了以下结果:) - 无法取消上传。上述方法取消页面接收响应,文件正在上传到服务器端。 这是我的原型的标记:

      <form id="form1" runat="server">
      <div>
      <asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
      
      <input type="button" id="button1" value="stopUpload" onclick="stopUpload()"/>
         <script type="text/javascript">
      
              function stopUpload() {               
                  var frame = $get("iframe1");
                  frame.contentWindow.document.execCommand("Stop");                
              }
      
          </script>
      </div>
      </form>
      <form id="form2" enctype="multipart/form-data" action="http://localhost/TestingSite/Default.aspx"
      method="POST" target="iframe1">
      <input type="submit" />
      <input type="file" name="FileUploadTest" id="FileUploadTest"/>
      </form>
      <iframe id="iframe1" name="iframe1" width="500px" height="500px" ></iframe>
      

      【讨论】:

      • 为什么这个解决方案对我不起作用我停止了页面但上传过程仍在继续
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-13
      • 2018-09-11
      • 2017-07-12
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多