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

我在页面上显示的动态链接(其余部分)可能会导致jpeg,tif或pdf文件在响应中。如何显示图像(img)或pdf(iframe)?

我试图做这样的(图像部分工作正常):

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。

感谢

+1

到底会发生什么(或者没有按”当它是一个PDF?你的iFrame是否显示,你可以用“你好”来测试它。自然从你的浏览器打开PDF文件,从其他网站说?因为您的PDF可以在阅读器中打开页面或在独立阅读器应用程序中打开。 –

+0

对不完整的帖子感到抱歉,但我不确定会发生什么情况,因为成功回调永远不会被调用。当我调试jQuery时,我发现它导致某种“无传输”错误。我不完全知道如何在ajax请求中介入(设置断点),以便我可以看到发生了什么?整个阿贾克斯块被踩过了。这有什么窍门吗? –

+0

它的工作原理!也许这是跨域问题。出于测试目的,该患者(我)使用来自某个随机网站的PDF URL。在我的REST服务中添加pdf支持后,它开始工作。

无论如何,谢谢。 –

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值