如何使用网址在Internet Explorer上下载Excel文件

问题描述:


我使用URL从我的服务器使用Internet Explorer下载Excel文件时遇到问题。
我有下面的代码在我的PHP脚本
如何使用网址在Internet Explorer上下载Excel文件

echo "<script> 
     window.location='http://localhost/complaint/export/export_complaint.xls'; 
    </script>"; 

该脚本可以当我使用的是Chrome浏览器中创建自动下载的动作,但在Internet Explorer中无法正常工作。
和我使用Internet Explorer 9.
请告知,如果有任何建议这个问题。非常感谢 !

+0

加上'类型=“文/ JavaScript的”'属性'script'标签 – Ander2 2013-03-14 08:09:36

+0

感谢@ Ander2,它工作时,我下载的Excel 2003格式,但Excel 2007格式仍然失败 – user1875301 2013-03-14 08:17:30

+0

@ user1875301检查我的答案,它将工作使用'jQuery'下载文件 – 2013-03-14 08:18:37

如果您不需要重定向与javascript做你可以用PHP这样的重定向:

header("Location: http://localhost/complaint/export/export_complaint.xls") 
+0

这一个是简单的结论。谢谢@ Ander2 – user1875301 2013-03-14 08:49:48

使用jQuery这个

在jQuery中:

$('a#someID').attr({target: '_blank', 
        href : 'http://localhost/complaint/export/export_complaint.xls'}); 

如果点击该链接,就会下载文件在新标签/窗口。

+1

嗨Sumit,我真的很感激你的建议。非常感谢! 但实际上我是一个开发人员的新手。 我认为@ Ander2的答案对我来说很简单。 – user1875301 2013-03-14 08:50:48