簡體   English   中英

在IE中提交表單時,iframe加載不起作用

[英]iframe load doesn't work when form submit in IE

我想在IE9中上傳文件,並且使用了表格和iframe。 這是我的html代碼:

<iframe name="ie9Iframe" ref="iframe" src="" width="0" height="0"></iframe>
<form ref="uploadForm" target="ie9Iframe" action="/pages/upload" method="post" enctype="multipart/form-data">
     <input class="fileChoose" type="file" name="upload_file" @change="fileChanged" id="file"/>
    <input type="submit" value="提交" id="fileSubmit"/>
</form>

這是我的js綁定onload事件:

   var iframe = document.getElementsByName('ie9Iframe')[0];
   console.log(iframe.toString());
   if(iframe.attachEvent) {
     console.log('attachevent')
     iframe.attachEvent('onload', function () {
       console.log(11111111111111)
       var responseText = iframe.contentDocument.body.textContent;
       console.log(responseText)
       if(responseText == '') {
           return;
       }
       var responseData = JSON.parse(responseText) || {};
           console.log(22222222222222222222)
           console.log(JSON.stringify(responseData))
           if(responseData.status == 1) {
              this.fileId = responseData.protocol.file_id;
           }
        })
   }else {
        console.log('notAttachevent')
   }

這是我的控制台日志:

日志: [object HTMLIFrameElement] 
日志: attachevent 
日志: 11111111111111 
日志:  

當我提交表單時,它返回一些json數據,但未調用iframe onload事件,因此無法獲取數據。 我嘗試了很多方法,但是它們沒有用。任何建議或評論都將很棒。

執行了onload事件(您將在111111111日志中包含onload塊代碼。腳本的問題是獲取iframe內容的代碼。

嘗試以下方法:

var responseText = iframe.document.body.textContent;

您應該在Internet Explorer上以稍微不同的方式獲取iframe文本內容。 檢查以下鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM