jquery 显示另存为
$(function(){
$(".btnPdf").click(function(){
var url=window.location.href;
$.post("action/pdf.ashx",{url:url},function(result){
window.location.href = 'pdf/'+result;
});
});
});
window.location.href = 'pdf/'+result;//result = text.pdf
这里怎么让他显示另存为或保存,不要在当前页面打开
高手解答 jQuery JavaScript URL asp.net --------------------编程问答-------------------- execCommand --------------------编程问答--------------------
如果你的客户端没有安装有pdf阅读器是可以直接打开的,如果要想不管有没有都下载那就得交给aspx以流形式输出 --------------------编程问答-------------------- execCommand 是什么意思啊。
--------------------编程问答-------------------- 如果你的客户端没有安装有pdf阅读器是可以直接下载的 --------------------编程问答--------------------
window.location.href = 'pdf/'+result;//result = text.pdf
这里要怎么传给aspx页面啊。
--------------------编程问答-------------------- window.location.href ='down.aspx?file='+ escape( 'pdf/'+result);
down.aspx.cs
string DownAdress = Request["file"];
if (!File.Exists(Server.MapPath(DownAdress)))
{
Response.Write("下载的文件不存在!");
Response.End();
return;
}
using (FileStream fso = new FileStream(Server.MapPath(DownAdress), FileMode.Open,FileAccess.ReadWrite,FileShare.Inheritable))
{
string[] filename=DownAdress.Split(new char[]{'/'});
int len = Convert.ToInt32(fso.Length);
byte[] FileObj = new byte[len];
fso.Read(FileObj, 0, len);
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", HttpUtility.UrlEncode(filename[filename.Length - 1]), System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", len.ToString());
Response.ContentType = "application/octet-stream";
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.BinaryWrite(FileObj);
Response.Flush();
Response.Clear();
fso.Close();
} --------------------编程问答-------------------- 高手,谢谢。
补充:.NET技术 , ASP.NET