【发布时间】:2017-12-23 21:48:30
【问题描述】:
我正在使用以下代码从 AJAX 请求将 PDF 加载到窗口中:
$('#divEmbedPdf').empty();
var req = new XMLHttpRequest();
req.open('GET', '/api/read/file?p_key=<some key>', true);
req.responseType = 'blob';
req.setRequestHeader('SomeAuthHeader', 'SomeTokenValue');
req.onload = function (event) {
var fblob = req.response;
$('<iframe/>', {
src: window.URL.createObjectURL(fblob),
frameborder: 0,
marginheight: 0,
marginwidth: 0,
css: {
position: 'absolute',
width: '100%',
height: '100%'
}
}).appendTo($('#divEmbedPdf'));
}
req.send();
这在 Chrome 和 FF 中运行良好,但 Edge 抛出以下错误:
SEC7134: Resource 'blob:C88E2211-80B6-4933-B5E1-0E8DE3665368' not allowed to load.
有没有办法让它与 Edge 一起工作?我不想打开一个新窗口,因为它在一个弹出窗口中运行,我希望在不打开和关闭的情况下看起来持久。正如您将注意到的,我在身份验证请求中发送了一个自定义标头,因此我不能只制作一个 iframe 并将 src 属性设置为路径。
【问题讨论】:
标签: javascript ajax pdf blob