I saw this code from the answer to the previous stack question:
if (iframeObj.contentWindow.document.execCommand)
{ // IE browsers
iframeObj.contentWindow.document.execCommand('Stop');
}
else
{ // other browsers
iframeObj.contentWindow.stop();
}
The question can be seen here . But basically the question he asked was that a hidden iframe could stop the file from loading.
Now I have a Cancel button, when I upload a file, if I want to cancel the download, then if I click Cancel, I want the file to stop downloading.
But my question is, what with the iframe that I have and the Cancel button that I use, how is it implemented so that the above code can be used to cancel the file upload in my code?
Below is the form code, which consists of the form and 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;
}