简体   繁体   English

XAMPP iframe在本地主机中不起作用

[英]XAMPP iframe not working inside localhost

I am trying to use an iframe to embed a pdf into a webpage. 我正在尝试使用iframe将pdf嵌入到网页中。 for some reason the pdf wont display (appears blank) and i'm prompted to download the file. 由于某种原因,pdf将不会显示(显示为空白),并提示我下载文件。 This happens when i run the code from localhost server. 当我从本地服务器运行代码时,就会发生这种情况。 however if i run the code outside localhost the iframe displays the pdf doc as it should. 但是,如果我在localhost之外运行代码,则iframe会按原样显示pdf文档。 i have also tried using <embed> , <object> and pdf.js they all gave the same outcome. 我也尝试使用<embed><object>和pdf.js,它们都给出了相同的结果。

PHP FILE PHP文件

echo'<div class="main_content_view">
<iframe  src="pdf/pdf1.pdf" id="pdf_content"
width="700px" height="800px">
</iframe>
</div>
 ';

i've also tried adding $cfg['AllowThirdPartyFraming'] = true; 我也尝试添加$cfg['AllowThirdPartyFraming'] = true; to the config.inc.php and it still didnt work. 到config.inc.php,它仍然无法正常工作。 Any ideas on how i could get the pdf to display in localhost as it does when i right click and open the php directly with a browser? 当我右键单击并直接使用浏览器打开php时,关于如何使pdf显示在localhost中的任何想法?

The thing is probably that a simple iFrame does not support viewing a PDF file. 问题可能是简单的iFrame不支持查看PDF文件。 And afaik PDF.js is only for Firefox browser but I am not entirely sure about that. afaik PDF.js仅适用于Firefox浏览器,但我对此并不完全确定。 What you can try is PDFObject . 您可以尝试的是PDFObject This lets you dynamically embed your PDF in HTML documents using JS. 这使您可以使用JS将PDF动态地嵌入到HTML文档中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM