Render pdf from other domain in HTML

2019-02-19 09:10发布

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

The html is:

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

And the javascript:

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

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

Thanks.

1条回答
SAY GOODBYE
2楼-- · 2019-02-19 09:17

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" />');

Demo

Try before buy

查看更多
登录 后发表回答