以前のスタックオーバーフローの質問に対する回答からこのコードを見ました:
if (iframeObj.contentWindow.document.execCommand)
{ // IE browsers
iframeObj.contentWindow.document.execCommand('Stop');
}
else
{ // other browsers
iframeObj.contentWindow.stop();
}
質問はここで見ることができますが、基本的に彼が尋ねた質問は、非表示の 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;
}