【问题标题】:How to use url to download Excel file on Internet Explorer如何使用 url 在 Internet Explorer 上下载 Excel 文件
【发布时间】:2013-03-14 16:23:38
【问题描述】:


当我使用 URL 使用 Internet Explorer 从我的服务器下载 Excel 文件时遇到问题。
我的 PHP 脚本中有以下代码

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

当我使用 Chrome 作为浏览器时,此脚本可以创建自动下载操作,但在 Internet Explorer 中不起作用。
我使用的是 Internet Explorer 9。
如果对此问题有任何建议,请告知。非常感谢!

【问题讨论】:

  • type="text/javascript"属性添加到script标签
  • 感谢@Ander2,当我下载 Excel 2003 格式时它可以工作,但对于 Excel 2007 格式仍然失败
  • @user1875301 检查我的答案,它可以使用jQuery 下载文件

标签: php javascript excel internet-explorer


【解决方案1】:

如果您不需要使用javascript 进行重定向,您可以使用PHP 进行重定向,如下所示:

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

【讨论】:

  • 这是一个简单的结论。谢谢@Ander2
【解决方案2】:

为此使用 jQuery

在 jQuery 中:

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

只要点击该链接,它就会在新的标签/窗口中下载文件。

【讨论】:

  • 您好 Sumit,非常感谢您的建议。非常感谢!但实际上我是开发人员的新手。我认为@Ander2 的答案对我来说很简单。
猜你喜欢
  • 2014-12-10
  • 2012-05-29
  • 2016-12-23
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
  • 2022-01-10
  • 2016-04-29
相关资源
最近更新 更多