【发布时间】:2012-05-03 00:59:53
【问题描述】:
我从上一个 stackoverflow 问题的答案中看到了这段代码:
if (iframeObj.contentWindow.document.execCommand)
{ // IE browsers
iframeObj.contentWindow.document.execCommand('Stop');
}
else
{ // other browsers
iframeObj.contentWindow.stop();
}
问题可以查看here但基本上他问的问题是隐藏的iframe是否有可能阻止文件上传。
现在我有一个“取消”按钮,当我上传文件时,如果我想取消上传,然后如果我点击“取消”按钮,我希望文件的上传停止。
但我的问题是,对于我拥有的 iframe 和我拥有的“取消”按钮功能,它是如何实现的,以便可以使用上面的代码在我的代码中取消文件上传?
以下是由表单和 iframe 组成的表单代码:
var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return stopImageUpload(this);' class='imageuploadform' >" +
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +
"</p><p class='imagef1_cancel' align='center'><label>" +
"<input type='button' name='imageCancel' class='imageCancel' value='Cancel' /></label>" +
"<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>");
下面是开始上传图片的startImageUpload函数,取消按钮点击处理函数显示在该函数中:
function startImageUpload(imageuploadform){
$(".imageCancel").click(function() {
$('.upload_target').get(0).contentwindow
return stopImageUpload();
});
return true;
}
【问题讨论】:
标签: javascript jquery