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

用javascript如何实现左键单击下载功能
RT,在线等高人指点

------解决方案--------------------
<A href= "filepath "> </a> 这样不能左键下载么?
------解决方案--------------------
<A href= "filepath "> </a> 这样不能左键下载么?
点保存不好了
------解决方案--------------------
用一个页面专门返回下载的文件~~~把文件地址传过去~~

设置http响应头让浏览器识别为文件下载,返回文件~~
------解决方案--------------------
我只会用ASP作这个功能
http://tzzhengda.com/119/dw/fifde.htm
这个网站上就是楼主说的功能,楼主看一下吧。所它的代码下来。自己看一下
------解决方案--------------------
看看这个 http://www.haolla.com/girls/index.asp
http://haolla.com/wy
------解决方案--------------------
onclick= "document.execCommand( 'saveas ', 'true ', 'linkname ') "
------解决方案--------------------
到download.csdn.net看下有没
------解决方案--------------------
<A href= "download.html "> download </a>
============
在download.html里实现下载。
------解决方案--------------------
回复人:ishion(爱森) ( 四级(中级)) 信誉:100 2007-3-10 16:54:46 得分:0
onclick= "document.execCommand( 'saveas ', 'true ', 'linkname ') "

这个就是可以的,当然也可以换个写法:
<a href= "javascript:document.execCommand( 'saveas ', 'true ', 'linkname '); "> download </a>

这个应当只适应于IE,在FF下需要另一个方法,另外如何要保存HTML全部内容,需要引用ActiveX控 件,网上有可以查一下
------解决方案--------------------
给个php的

js
href= "downfile.php?path=xxx "
===============
downfile.php
<?
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
$filesize=0;
if(file_exists($qm[ "path "]))
$filesize=filesize($qm[ "path "]);
Header( "Content-Length: ".$filesize);
Header( "Content-Disposition: attachment; filename= ".basename($qm[ "path "]));
readfile($qm[ "path "]);
exit;
?>