img pdf 展示_如何显示图像(img)或pdf(iframe)?

本文档探讨了在网页上显示动态获取的JPEG、TIFF图像和PDF文件的方法。通过使用Ajax和jQuery处理Content-Type响应头,成功显示了图像。然而,对于PDF部分,尽管尝试了PDF.js,但由于客户使用IE8,遇到了兼容性问题。解决方案可能需要寻找支持IE8的PDF显示库或采用替代方法来确保在旧版浏览器上的兼容性。
摘要由CSDN通过智能技术生成

我在页面上显示的动态链接(其余)可能会在响应中生成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("");

}

},

complete: function(output){

$('#navigation-block').append(output);

},

error: function(output) {

$('#navigation-block').append(output);

}

});

}

PDF部分不起作用。

我该如何解决这个问题?

顺便说一下,我控制了REST服务器端和jQuery端,所以我在REST响应头中添加了正确的内容类型。

我检查了PDF.js并且会使用它,但不幸的是我的客户使用IE8。

由于

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值