【发布时间】:2022-07-22 21:48:40
【问题描述】:
我有以下代码来获取 PDF 文件并在新选项卡中打开它:
$(document).on('click', '#downloadInvoice', function () {
showLoader();
$.ajax({
type: 'POST',
url: _baseUrl + 'orders/downloadinvoice/' + $(this).data('id'),
xhrFields: {
responseType: 'blob'
},
success: (response) => {
const blob = new Blob([response], { type: 'application/pdf' }),
url = window.URL.createObjectURL(blob)
window.open(url);
},
error: () => {
toastr.error('Error!');
},
complete: () => {
hideLoader();
}
});
});
它在 Chrome 中按预期工作,但在 Firefox 中,它会自动下载文件,我必须在 Downloads 中查找它并手动打开它。
是 Firefox 阻止了新标签页的打开,还是我需要在我的代码中添加一些内容?奇怪的是,我在网上没有找到与此问题相关的任何内容。
【问题讨论】:
标签: javascript firefox