IE8 - IFRAME导致刷新整个页面

时间:2013-11-08 13:46:30

标签: javascript html iframe internet-explorer-8

我有一个基于IFRAME的上传器文件。它适用于Firefox和谷歌浏览器,但是当您发送整个页面的文件时,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>

1 个答案:

答案 0 :(得分:1)

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;
}