使用 iframe 在浏览器中显示几乎所有类型文档的简单解决方案。
解决方案是Google Docs Viewer
只需使用下面给出的iframe 并替换其中的文档网址即可。
<iframe src='https://docs.google.com/viewer?url=ENTER URL OF YOUR DOCUMENT HERE&embedded=true' frameborder='0'></iframe>
通过替换.docx文件的示例url,上面的代码变成了。
<iframe src='https://docs.google.com/viewer?url=http://calibre-ebook.com/downloads/demos/demo.docx&embedded=true' frameborder='0'></iframe>
通过替换.pdf文件的示例url,上面的代码变成了。
<iframe src='https://docs.google.com/viewer?url=http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf&embedded=true' frameborder='0'></iframe>
注意:需要在浏览器中显示的文档必须正确
url 并且必须公开,因为 Google 需要
获取并显示文档,如果文档是私有的并且处理失败
您将看到 iframe 和 NO PREVIEW AVAILABLE