【问题标题】:I am not able to get the file open in new window when i use window.open()当我使用 window.open() 时,我无法在新窗口中打开文件
【发布时间】:2019-02-13 06:08:10
【问题描述】:

我正在使用此代码打开一个文件,它会在控制台中显示 url,但不会在新窗口中打开它。

ft.openFile = function(id) {
  FileService.download(id).then(function(resp) {
    console.log(resp.headers('Content-Type'));
    var blob = new Blob([resp.data], {
      type: resp.headers('Content-Type')
    });
    var url = $window.URL || $window.webkitURL;
    var fileUrl = url.createObjectURL(blob);
    window.open(fileUrl);
    console.log(fileUrl);
})

【问题讨论】:

  • 当您使用 winodw.open() 时,可能需要浏览器权限。您应该必须在浏览器中允许弹出窗口。

标签: node.js angularjs mongodb express


【解决方案1】:
 ft.openFile = function(id){
 FileService.download(id).then(function(resp){
    console.log(resp.headers('Content-Type'));
    var blob = new Blob([resp.data],{type: resp.headers('Content-Type')});
    var url = $window.URL||$window.webkitURL;
    var fileUrl = url.createObjectURL(blob);

    window.open(fileUrl, '_self'); //same window

    //or

    window.open(fileUrl, '_blank'); //new window

    console.log(fileUrl);
 })

【讨论】:

    【解决方案2】:

    使用这个:

    window.open(fileUrl, '_blank'));
    

    【讨论】:

      猜你喜欢
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      • 2013-04-04
      相关资源
      最近更新 更多