从HTML中的其他域渲染pdf [英] Render pdf from other domain in HTML

查看:170
本文介绍了从HTML中的其他域渲染pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在其他网域的网页中呈现PDF。

I'm trying to render a PDF in my web page from another domain.

HTML是:

<div id="pdfContainer">
    <embed id="pdf" type="application/pdf" />
</div>

和javascript:

And the javascript:

$.get("http://otherDomain/Files/Pdf/some.pdf", function(data) {
    $("#pdf").prop("src", data);
});

但是我有一个跨域错误。有办法吗?使用PHP可能?

But of course I have a cross domain error. Is there a way to do it? With PHP maybe?

谢谢。

推荐答案

scr - < embed> -tag的属性,它会真正改变属性,更改嵌入对象本身。我认为改变或使已经嵌入的对象可见的唯一方法是:

If you change the scr-attribute of an <embed>-tag, it will really change the attribute, but it won't change the embedded object itself. I think the only ways to change or to make an already embedded object visible are:

// hide it in the beginning and show it on demand
$("#pdf").show();

// replace the whole node
$("#pdfContainer").html('<embed src="[URL]" type="application/pdf" />');

演示

购买之前尝试

这篇关于从HTML中的其他域渲染pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆