Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法在IE中从服务器下载文件_Angular_File_Typescript_Internet Explorer_Download - Fatal编程技术网

Angular 无法在IE中从服务器下载文件

Angular 无法在IE中从服务器下载文件,angular,file,typescript,internet-explorer,download,Angular,File,Typescript,Internet Explorer,Download,我正在尝试为我的用户生成一个文本文件,下面的代码在除IE和Edge之外的所有浏览器中都能很好地完成这项工作(在后者中,我无法控制文件名,但至少生成了该文件) 在这方面是有争议的,但它的日期是18个月前,最近的活动是相当不最近的。这似乎是一个希望破灭的地方 我还没有找到任何合理的解决办法。我所看到的要么是不起作用的,要么是(非常明智但不可行的)为了duck的缘故建议使用体面的浏览器。我相信这更多的是一个打字错误,而不是一个鸟的参考 应该怎么做?您应该尝试使用msSaveBlob()而不是“下载”属

我正在尝试为我的用户生成一个文本文件,下面的代码在除IE和Edge之外的所有浏览器中都能很好地完成这项工作(在后者中,我无法控制文件名,但至少生成了该文件)

在这方面是有争议的,但它的日期是18个月前,最近的活动是相当不最近的。这似乎是一个希望破灭的地方

我还没有找到任何合理的解决办法。我所看到的要么是不起作用的,要么是(非常明智但不可行的)为了duck的缘故建议使用体面的浏览器。我相信这更多的是一个打字错误,而不是一个鸟的参考


应该怎么做?

您应该尝试使用msSaveBlob()而不是“下载”属性

emitFile(stage: any): void {
  const blob = new Blob([stage.elaboration], { type: "text/csv" });
  window.navigator.msSaveBlob(blob,"ff-rocks-ie-sucks.txt");
}
它应该适合IE和Edge

编辑: IE、FF和Chrome的完整解决方案如下:

emitFile(stage: any): void {
  const blob = new Blob([stage.elaboration], { type: "text/csv" });
  if(window.navigator.msSaveOrOpenBlob) //IE & Edge
  {
    //msSaveBlob only available for IE & Edge
    window.navigator.msSaveBlob(blob,"ff-rocks-ie-sucks.txt");
  }
  else //Chrome & FF
  {
    const url = window.URL.createObjectURL(blob);
    const anchor = document.createElement("a");
    anchor.href = url;
    anchor.download = "ff-rocks-ie-sucks.txt";
    document.body.appendChild(anchor); //For FF
    anchor.click();
    //It's better to remove the elem
    document.body.removeChild(anchor);
  }
}

您应该尝试使用msSaveBlob()而不是download属性

emitFile(stage: any): void {
  const blob = new Blob([stage.elaboration], { type: "text/csv" });
  window.navigator.msSaveBlob(blob,"ff-rocks-ie-sucks.txt");
}
它应该适合IE和Edge

编辑: IE、FF和Chrome的完整解决方案如下:

emitFile(stage: any): void {
  const blob = new Blob([stage.elaboration], { type: "text/csv" });
  if(window.navigator.msSaveOrOpenBlob) //IE & Edge
  {
    //msSaveBlob only available for IE & Edge
    window.navigator.msSaveBlob(blob,"ff-rocks-ie-sucks.txt");
  }
  else //Chrome & FF
  {
    const url = window.URL.createObjectURL(blob);
    const anchor = document.createElement("a");
    anchor.href = url;
    anchor.download = "ff-rocks-ie-sucks.txt";
    document.body.appendChild(anchor); //For FF
    anchor.click();
    //It's better to remove the elem
    document.body.removeChild(anchor);
  }
}

IE11不支持下载属性。使用文件:协议时,IE中的结果不同。或者本地主机,而且没有解决办法?我希望它有可能以某种方式实现。我想我运气不好。。。请将其作为回复发布,以便(不情愿地)接受。:)IE11不支持下载属性。使用文件:协议时,IE中的结果不同。或者本地主机,而且没有解决办法?我希望它有可能以某种方式实现。我想我运气不好。。。请将其作为回复发布,以便(不情愿地)接受。:)您是否建议
emitFile
方法应该识别应用程序在哪个浏览器中运行,并做出相应的反应?或者有没有一种方法可以根据特定的标记调用它的正确版本?没有,由于msSaveBlob函数,此解决方案只能在IE和Edge上工作。您需要为FF和Chrome添加一个条件:
if(window.navigator.msSaveOrOpenBlob)//IE&Edge{}else{//Chrome&FF}
您是否建议
emitFile
方法应该识别应用程序在哪个浏览器中运行并做出相应的反应?或者有没有一种方法可以根据特定的标记调用它的正确版本?没有,由于msSaveBlob函数,此解决方案只能在IE和Edge上工作。您需要为FF和Chrome添加一个条件:
if(window.navigator.msSaveOrOpenBlob)//IE&Edge{}else{//Chrome&FF}