用Javascript隐藏超级链接的真实地址

用Javascript可以隐藏超级链接的真实地址:
在显示下载链接的页sample.aspx的前台合适地方加入以下代码如下:
<href="#" onclick="javascript:window.open('DownLoad.aspx?ID=11','newwin','width=350,height=510,scrollbars=0,toolbar=0,resizable=0')">打开窗口</a> 

通过DownLoad.aspx文件读取需下载的文件信息,在后台加入代码:
 
try
            
{
                
string str = "select FileContent,FileType, FileName from fileinfo where id = " + base.Request.QueryString["id"];
                SqlDataReader Dr 
= pubValue.DataRead(str);

                
string strfilePath = "file/" + base.User.Identity.Name;
                
string path = "";

                
if (Dr.Read())
                
{
                    
string s = Dr["FileName"].ToString();
                    path 
= base.Server.MapPath(strfilePath + "/" + s);

                    
if (File.Exists(path))
                    
{
                        File.Delete(path);
                    }


                    FileStream stream 
= new FileStream(path, FileMode.Create);
                    stream.Write((
byte[])Dr["FileContent"], 0, ((byte[])Dr["FileContent"]).Length);
                    StreamWriter writer 
= new StreamWriter(stream);
                    writer.WriteLine(
"");
                    writer.Flush();
                    writer.Close();
                    stream.Close();
                    
base.Response.Write("<script>location.href='" + strfilePath + "/" + base.Server.UrlEncode(s).Replace("+""%20"+ "';</script>");
                }

            }

            
catch (Exception exception)
            
{
                
base.Response.Write(exception.Message);
            }

当鼠标打向打开窗口时,出现的链接信息是#,而不是下载文件的链接地址,从而达到隐藏真实的超级链接地址的效果!

posted on 2007-11-16 15:58    阅读(1309)  评论(0编辑  收藏  举报

导航