如何修复处理 iframe 的此错误

How to fix this error dealing with an iframe

本文关键字:错误 iframe 何修复 处理      更新时间:2023-09-26

当用户单击"取消"按钮时,我正在尝试阻止文件上传。为此,我正在考虑停止 iframe 内的传输。问题是能够正确编码。以下是我试图实现的代码,但是当我单击"取消"按钮时出现此错误:

Uncaught exception: [Exception.... “Not enough arguments [nslDOMHTML.Document.execCommand]” nresult: “0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)” location: “JS frame;; https://......../QandATable.php = <TOP_LEVEL> ;; line 765” data: no]

首先如何修复此错误,其次如何正确编写下面的代码,以便在单击"取消"按钮时停止iframe内的传输?

下面是开始上传文件的 startImageUpload() 函数。在该函数中,有在单击"取消"按钮时处理"取消"按钮的功能;

function startImageUpload(imageuploadform){

              $(".imageCancel").click(function() {
              $('.upload_target')[0].contentwindow
              if ($('.upload_target')[0].contentWindow.document.execCommand)
    { // IE browsers
       $('.upload_target')[0].contentWindow.document.execCommand('Stop');
    }
else
    { // other browsers
        $('.upload_target')[0].contentWindow.stop();
    }

          return stopImageUpload();
    });
      return true;
}

下面是由 iframe 组成的表单代码:

 var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target' onsubmit='return startImageUpload(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></p>" + 
    "<iframe class='upload_target' name='upload_target' src='#' style='width:0;height:0;border:0px;solid;#fff;'></iframe></form>"); 

根据 MSDN,不支持Stop命令。