IE8 - IFRAME 会导致整个页面刷新

IE8 - IFRAME causes refresh of entire page

本文关键字:刷新 IFRAME IE8      更新时间:2023-09-26

我有一个基于 IFRAME 的上传器文件。它适用于Firefox和Google Chrome,但是在Internet Explorer 8中,当您发送整个页面的文件时,会刷新。按照我的代码:

.JS:

  function test(){
     iframe = document.createElement("IFRAME");  
     iframe.name = "iframe_upload";
     iframe.id = "iframe_upload"; //some browsers target by id not name
     document.body.appendChild(iframe);
     document.getElementById("test").target = "iframe_upload";
  }

.HTML:

<form id="test" method="post" target="iframe_upload" enctype="multipart/form-data" onsubmit="javascript:test()" action="test.php">
  <input name="image" type="file" /> 
  <input type="submit" value="Submit" />
</form>

onsubmit操作返回:

onsubmit="return test();"

并从函数返回false

function test(){
   iframe = document.createElement("IFRAME");  
   iframe.name = "iframe_upload";
   iframe.id = "iframe_upload"; //some browsers target by id not name
   document.body.appendChild(iframe);
   document.getElementById("test").target = "iframe_upload";
   return false;
}