2013-07-16 56 views
2

我想从另一个域中呈现我的网页中的PDF。从HTML中的其他域呈现PDF

的HTML是:

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

和JavaScript:

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

但是,当然,我有一个跨域错误。有没有办法做到这一点?用PHP也许?

谢谢。

+1

嗯,为什么不干脆直接点'embed'到外部URL ? '(“#pdf”)。prop(“src”,“http://otherDomain/Files/Pdf/some.pdf”);' –

+1

只需删除外部ajax函数,就不能将所有数据添加到无论如何,该文件到src属性。 – adeneo

+0

@Pekka웃是的,这是我做的第一件事,但我得到了:Access-Control-Allow-Origin不允许使用Origin http:// domain。无法加载资源:服务器的状态为403(禁止).' @adeneo那么该怎么办? – Maxbester

回答

1

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

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

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

演示

Try before buy

+0

谢谢!有用。 – Maxbester