日期:2014-05-16  浏览次数:20365 次

JS下载附件问题
parent.html
=================================
<script language="javascript"> 
<!-- 
function openChild(){ 
 var k = window.showModalDialog("child.html",window,"dialogWidth:335px;status:no;dialogHeight:300px;");

</script> 
<input type ="button" value="转到子页面" onClick="openChild();">
=================================
child.html
=================================
<script language="javascript">
function downloadFile() {  
 
  url = "xxxx.rar";
  var elemIF = document.createElement("iframe");  
  elemIF.src = url;  
  elemIF.style.display = "none";  
  document.body.appendChild(elemIF);  
}
</script> 
<div class="login_center">
  <input type="button" onClick="downloadFile('')" value="点击">
</div>
现在单击onclick事件能下载附件。
但是需要的是页面一载入就想调用downloadFile()方法。
然后这样写 <body onLoad="downloadFile('')"></body>
就发现IE不弹下载附件,如何解决?

------解决方案--------------------
这个是为了安全性考虑这样设计的
js无法实现,可以用服务器代码实现,想直接弹出下载只能在后台往前台写文件
网上搜一搜吧,很多,就是用Response.Write实现这个功能