我在页面(其余)上显示的动态链接可能会导致响应中出现 jpeg、tif 或 pdf 文件。
我试着这样做(图像部分工作正常):
fetchContent(uri){
$.ajax({
type: "GET",
url: uri,
success: function(output, status, xhr) {
var contentType = xhr.getResponseHeader("Content-Type");
if(contentType === "image/jpeg" || contentType === "image/tiff"){
// IMG: get parent div 'container'
var $container = $('#container', top.frames["content"].document);
var img = new Image();
$(img)
.load(function(){
// initially hide
$(this).hide();
$(this).attr('id', 'imgId');
// parent div:
$container
// remove previous image
.empty()
// add this image
.append(this);
// fade in image effect
$(this).fadeIn();
})
// set the src attribute of the new image to our image
.attr('src', uri);
}else if(contentType === "application/pdf"){
// PDF: get parent div 'main'
var $main = $('#main', top.frames["content"].document);
$main.empty();
$main.append("<iframe id='contentIFrame' name='contentIFrame' src='" + uri +
"' width='100%' style='height:100%'></iframe>");
}
},
complete: function(output){
$('#navigation-block').append(output);
},
error: function(output) {
$('#navigation-block').append(output);
}
});
}
PDF 部分不起作用。
我该如何解决?
顺便说一句,我控制 REST 服务器端和 jQuery 端,所以我在 REST 响应标头中添加了正确的内容类型。
我检查了 PDF.js 并且会使用它,但不幸的是我的客户使用 IE8。
谢谢