问一个浏览器兼容的问题

小雄 2014-09-04 11:19:10
最近在一个网站,需要用到弹出框,代码如下:
 protected void Button1_Click(object sender, EventArgs e)
{
//1
string script = string.Format(CultureInfo.CurrentCulture, "<script>alert('{0}');</script>", "弹出框");
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "提示", script);
//2
Response.Write("<script type='text/javascript'>alert('ssss');</script>");
}

由于客户用到的是IE9跟IE11。。在11下是正常能弹出的。为嘛在9下无效。
ps:2种方法都试过了。。

然后还有一段下载文件的代码:
 /// <summary>
/// 下载指定路径的文件
/// </summary>
/// <param name="filePath">相对路径文件,如"~\Upload\Test.xls"</param>
public static void DownloadFile(string filePath)
{
string path = HttpContext.Current.Server.MapPath(filePath);
FileInfo toDownload = new FileInfo(path);

if (toDownload.Exists)
{
const int chunkSize = 10000;
byte[] buffer = new byte[chunkSize];

HttpContext.Current.Response.Clear();
using (FileStream stream = File.OpenRead(path))
{
long dataLengthToRead = stream.Length;
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpContext.Current.Server.UrlEncode(toDownload.Name));
while (dataLengthToRead > 0 && HttpContext.Current.Response.IsClientConnected)
{
int lengthRead = stream.Read(buffer, 0, chunkSize);
HttpContext.Current.Response.OutputStream.Write(buffer, 0, lengthRead);
HttpContext.Current.Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
}
}

HttpContext.Current.Response.Close();

}
}

这个在IE9下面也是无效的。。求解。求指导。。
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
by_封爱 2014-09-04
  • 打赏
  • 举报
回复

public static void downloadfile(string s_fileName)
    {
        HttpContext.Current.Response.ContentType = "application/ms-download";
        string s_path = HttpContext.Current.Server.MapPath("~/") + s_fileName;
        System.IO.FileInfo file = new System.IO.FileInfo(s_path);
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
        HttpContext.Current.Response.Charset = "utf-8";
        HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
        HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
        HttpContext.Current.Response.WriteFile(file.FullName);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.End();
    }
这个代码也经历了很多年 很多版本的IE也没什么问题..
by_封爱 2014-09-04
  • 打赏
  • 举报
回复

public static void show(Page page, string str)
{
    page.ClientScript.RegisterStartupScript(page.GetType(), "", "<script language='javascript'>alert('" + str + "');</script>");
}
上面的代码从6运行到11 (IE) 并且用了5年以上 没问题..
rayyu1989 2014-09-04
  • 打赏
  • 举报
回复
按F12 在控制台中看看js报什么错误

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧