2011-07-18 36 views
3

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

在此先感谢。

+0

尝试移除iframe,或将iframe的位置设置为不同的网址。 – Gerben

回答

1

感谢您的回复。 据我调试的情况下,我得到了以下结果:) - 这是不可能取消上传。上面的方法取消了页面以接收响应,并且文件正在上传到服务器端。 这里是我的原型的标记:

<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> 
+0

为什么这个解决方案不适用于我我停止了该页面,但上传过程仍在继续 – Marwan

1

您可能需要沿着window.stop()(应用于iframe)的方向行事。

This old thread报告虽然window.stop()在IE中不起作用,但未公开的window.document.execCommand("Stop")确实(至少在IE5中)。

你也可以咨询this StackOverflow page,它基本上有相同的答案,尽管提出了一些其他的技巧。

2

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

问题是,从servlet发送的指示'文件太大'的响应未触发目标iframe onload事件。

尝试:

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

这上当了iframe onload事件触发将自动取消上传。