关于javascript:如何在iFrame中加载PDF文件? 在React中工作

How to load PDF file inside of iFrame? Working in React

我正在尝试在REACT的iFrame中加载pdf文件,代码如下所示:

1
2
3
4
5
6
7
8
9
10
render(){
   return(
      <iframe
          sandbox="allow-same-origin allow-scripts allow-forms"
          title="PortletIFrameWidget"
          src={'.resources/crayola.pdf'}
          ref={(f) => { this.ifr = f }}
      />
   )
}

我收到警告:

Resource interpreted as Document but transferred with MIME type
application/pdf:"http://localhost:8080/resources/crayola.pdf"

但是当我转到链接:" http:// localhost:8080 / resources / crayola.pdf"时,我可以很容易地看到PDF的内容,因此存在pdf文件,问题是:它没有在其中上传/呈现 iFrame。 为什么?

这在MOZILLA FIREFOX和Edge中起作用,但在CHROME中不起作用。

知道为什么会这样吗? 以及如何在REACT中的iFrame中加载PDF文件


这与React无关,问题显然出在GOogle-Chrome中。
这是我做的解决方案:

1
2
3
<iframe src="./resources/crayola.pdf" title="title">
     Presss me: Download PDF
</iframe>

以及对我有帮助的链接:
PDF对象