1
如何打开显示AJAX请求的流式响应的新窗口?使用Javascript在新窗口中打开PDF流
如何打开显示AJAX请求的流式响应的新窗口?使用Javascript在新窗口中打开PDF流
其他类似的问题预设了一个场景,其中回答有defined url,其他答案是old。
对于现代的浏览器,您使用fetch你可以可以调用blob() on the returned response然后用URL.createObjectURL()创建一个临时的网址,您可以打开按正常的window.open()。
完整的例子就是像
fetch(urlThatReturnsDataOpenableByBrowser)
.then(response => response.blob())
.then(data => window.open(URL.createObjectURL(data)))