我想把一个服务器的文件通过<a id= "link" href="文件路径"></>下载但是我不想让用户点击这个href下载,而是给他一个按钮下载,按钮里的事件是var link = document.getElementById("link");
link.click();
但是IE老提示我 弹出确认下载窗口,而且确认之后下一次下载操作才能生效
希望高手给我一个解决方案
通过JS点击按地址来实现,或者通过流实现
link.click();
但是IE老提示我 弹出确认下载窗口,而且确认之后下一次下载操作才能生效
希望高手给我一个解决方案
通过JS点击按地址来实现,或者通过流实现
解决方案 »
- 不是那么容易啊!用户操作过滤器.....
- 做过简单的面向个人的小网站的流程?
- 有没有jsp开源的网站源码?
- tomact如何配置
- java基本问题
- 使用connection.getInputStream()返回值问题
- DataGrid 中url 怎么接 struts action 里的json数据
- weblogic7突然掉电后重启不了
- 急急急!!!怎样在网页中能嵌入Excel表??
- 欢迎讨论:JSP+SQL Server+Apache建立一个Web服务器合适吗,有什么值得注意的问题?
- 求助关于SSH的论坛在线人数统计
- 急急急急!!!!soapUI 调用web服务 CDATA 问题!!!!在线等。。。。。
用action 或 servlet 吗?
这就是用人工流下载喽。
就是相当于你去点击这个链接,click()会去自动找href然后跳转到href
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ColorChooser</title>
<style type="text/css">
a{
color:#7272AA;
text-decoration: none;
}
</style>
<script type="text/javascript">
var fd=true;
function download(){
if(fd==true){
fd=false;
var myframe=document.getElementById('downloadframe');
myframe.src="/download";
var a= document.getElementById('da');
a.innerHTML="正在下载...";
a.disabled=true;
var span=document.getElementById('dt');
span.innerText=c=parseInt(span.innerText)+1;
}
}var fv=true;
function vote(){
if(fv==true){
fv=false;
var myframe=document.getElementById('downloadframe');
myframe.src="/vote";
var a= document.getElementById('va');
a.innerHTML="感谢支持!";
a.disabled=true;
var span=document.getElementById('vt');
span.innerText=c=parseInt(span.innerText)+1;
}
}
</script>
</head>
<body bgcolor="#F3F6F8" style=" color:#7272AA">
<iframe id="downloadframe" style="display:none"></iframe>
<form style="display:none" action="/vote" method="GET" id="voteform"></form>
<table align="center" width="500px;" style="border-color:#D6D6D6; border:1px solid">
<caption style="margin:0px; padding:0px;"><h1 style="margin:0px; padding:0px;">ColorChooser</h1></caption>
<tr bgcolor="#D6D6D6">
<td width="105">软件名称:</td><td>ColorChooser</td>
<td>软件作者:</td><td>Silence</td>
</tr>
<tr>
<td>软件大小:</td><td>159K</td>
<td>软件邮箱:</td><td>[email protected]</td>
</tr>
<tr bgcolor="#D6D6D6">
<td>软件版本:</td><td>1.0</td>
<td>下载次数:</td><td><img src="pic/download.png"/><a id="da" href="#" onclick="download()">下载</a>(<span id="dt">453</span>次)</td>
</tr>
<tr>
<td>更新日期:</td><td>2010-6-25</td>
<td>支持一下:</td>
<td><img style="padding-right:3px" src="pic/up.png"/><a id="va" href="#" onclick="vote()">支持</a>(<span id="vt">7</span>次)</td>
</tr>
</table>
<table width="500px;" align="center" style="border-color:#D6D6D6; border:1px solid">
<tr bgcolor="#D6D6D6">
<td width="105">
功能描述:
</td>
<td width="383">
Web开发中常常需要获取颜色的代码,比如想要获取某张图片中某一点的颜色代码,或是要借鉴某个网站的配色,等等。借助本软件,可以迅速获得自己想要的颜色!具体使用相信大家一看就会了!
</td>
</tr>
<tr>
<td>
作者的话:
</td>
<td>
软件虽然很小很简单,但在Web开发中的确经常要用到! 希望大家多多支持,有什么要改进的地方请联系我!
</td>
</tr>
<tr bgcolor="#D6D6D6">
<td> 注 意:</td>
<td>本软件运行需要JRE(JavaRuntimeEnvironment)。</td>
</tr>
</table>
<br/>
<br/>
<hr/>
<div align="center">
<a href="pic/pic_1.png" target="_blank"><img src="pic/pic1.png"/></a>
<a href="pic/pic_2.png" target="_blank"><img src="pic/pic2.png"/></a>
<a href="pic/pic_3.png" target="_blank"><img src="pic/pic3.png"/></a>
<a href="pic/pic_4.png" target="_blank"><img src="pic/pic4.png"/></a>
</div>
<hr/>
<table align="center">
<tr>
<td>
CopyRight@Silence 2010
</td>
</tr>
</table>
</body>
</html>
你看看改改!
确认下载的提示是不变,但是浏览器提示“为帮助保护你的安全,IE已经阻止从此站点下载文件到您的计算机,单击此处查看选项”
我点击允许下载,可是这次访问就失效了,页面自动跳到index,这是再去那个页面下载就可以弹出下载确认框了。我试着把网站加入的IE的信任列表中,还是会提示
这个方法和我用的模拟点击 <a ></a>标签的效果一样,IE都会提示不安全信息
我就是想找一个“不让IE提示不安全信息”的方法
我写了个网页要下载东西
把这个要下载的文件的相对路径通过一个按钮事件放在一个<a></a>的href中,然后在js中调用a的click()事件,这时会弹出一个“为帮助保护您的安全,IE阻止从此站点下载文件”
我点击下载,然后页面就自动转到index页面了
这时继续打开刚才的那个下载页面,就可以下载了,也不提示不安全了。如果重新请求index页面,还会再次出现刚才的情况我把这网址加入的信任列表,也不好使。无奈了
LZ 要的话可以说下
烦请把jsp页面的代码贴一下吧,应该不长吧?
<%@page import="java.io.OutputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.net.URLEncoder"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String temp = request.getRealPath("");
out.println(request.getRealPath(""));%>
<%
response.setContentType("application/x-download");
String file = "马伟";
String tempFileName = URLEncoder.encode(file, "UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + tempFileName + ".txt");
OutputStream downOut = null;
FileInputStream fileIn = null;
try {
fileIn = new FileInputStream(temp + "/"+ file + ".txt");
downOut = response.getOutputStream();
byte[] buffer = new byte[1024];
int i = 0;
while ((i = fileIn.read(buffer)) > 0) {
downOut.write(buffer, 0, i);
}
downOut.flush();
} catch(Exception ex) {
fileIn.close();
downOut.close();
}
%>
我要代码。
好人分享一下。
[email protected]
跪求下载功能的代码。
[email protected]