Javascript文件下载不适用于IE6和IE7

时间:2010-10-21 19:54:23

标签: javascript asp.net internet-explorer-7 internet-explorer-6

我有以下代码

Response.TransmitFile(filePath);

使用以下代码行打开新窗口

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Download", string.Format("window.open('{0}', target = 'new');", downloadURL), true);

这适用于IE8,但不适用于IE6和IE7

在这里可能有什么问题?

1 个答案:

答案 0 :(得分:0)

您很可能会收到脚本错误

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Download", string.Format("window.open('{0}', target = 'new');", "http://example.com"), true);

应呈现javascript:

window.open('http://example.com', target = 'new');

在上面的脚本中,目标变量是未定义的。如果您希望在新窗口中打开链接,请尝试:

this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Download", string.Format("window.open('{0}', '_blank');", downloadURL), true);

查看here以获取window.open函数

的可用参数列表