我有兩種形式的頁面。其中一個不可見幷包含input type =「file」。我正在上傳帶有隱藏窗體的文件(窗體的目標是一個iframe元素)。我的問題是如何停止/取消在IE下使用javascript上傳文件。我試圖用JQuery刪除隱藏的表單,該文件仍在上傳。如何取消/停止在IE中上傳文件javascript
在此先感謝。
我有兩種形式的頁面。其中一個不可見幷包含input type =「file」。我正在上傳帶有隱藏窗體的文件(窗體的目標是一個iframe元素)。我的問題是如何停止/取消在IE下使用javascript上傳文件。我試圖用JQuery刪除隱藏的表單,該文件仍在上傳。如何取消/停止在IE中上傳文件javascript
在此先感謝。
感謝您的回覆。 據我調試的情況下,我得到了以下結果:) - 這是不可能取消上傳。上面的方法取消了頁面以接收響應,並且文件正在上傳到服務器端。 這裏是我的原型的標記:
<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>
爲什麼這個解決方案不適用於我我停止了該頁面,但上傳過程仍在繼續 – Marwan
您可能需要沿着window.stop()
(應用於iframe)的方向行事。
This old thread報告雖然window.stop()
在IE中不起作用,但未公開的window.document.execCommand("Stop")
確實(至少在IE5中)。
你也可以諮詢this StackOverflow page,它基本上有相同的答案,儘管提出了一些其他的技巧。
好的。我發現這個網站尋找相同的東西,但這些解決方案並不適用於我的場景。我也有我的表單的iframe目標,並希望取消上傳。這些解決方案由於某種原因無法工作(IE7)。我希望以下幫助。
問題是,從servlet發送的指示'文件太大'的響應未觸發目標iframe onload事件。
嘗試:
targetIframe.contentWindow.document.open()
targetIframe.contentWindow.document.close()
這上當了iframe onload事件觸發將自動取消上傳。
嘗試移除iframe,或將iframe的位置設置爲不同的網址。 – Gerben