我从 stackoverflow 获得了这段代码,它可以在浏览器中显示 word 文档。是否可以仅在本地主机中显示 word 文档。尝试此代码后 bcz ..它只显示“没有可用的预览”。 .
$(document).ready(function() {
$(".word").fancybox({
'width': 600, // or whatever
'height': 320,
'type': 'iframe'
});
});
<a class="word" href="http://docs.google.com/gview?url=http://domain.com/path/docFile.doc&embedded=true">open a word document in fancybox</a>
我的作品
$path="resume/".$row['resume'];
echo "<br /><a class='word' href='http://docs.google.com/gview?url=".$path."&embedded=true'>View Resume</a>";
我给的路径不正确吗?
最佳答案
你不能。浏览器没有任何内置的方式来查看 Word 文档,因此除非用户将浏览器配置为使用某些插件打开它(世界上 99% 的人都没有这样做),否则浏览器将提示他们下载文件.
因此,目前没有浏览器具有呈现 Word 文档所需的代码,而且据我所知,目前也没有用于呈现它们的客户端库。
您可以通过
使用 Google 文档的查看器<iframe src="http://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>
您可以在 SO link 查看解决方案
如果您想使用下载脚本打开文件,则可以使用
Content-type: application/vnd.ms-word
<?php
header('Content-type: application/vnd.ms-word');
header('Content-Disposition: attachment; filename="document.doc"');
readfile('path-to-file.docx');
?>
您可以使用 office live apps viewer ,需要互联网连接://view.officeapps.live.com/op/embed.aspx?src=your_url_here
将此 url 放在 iframe 中
<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=http://remote.url.tld/path/to/document.doc' width='1366px' height='623px' frameborder='0'>This is an embedded <a target='_blank' href='http://office.com'>Microsoft Office</a> document, powered by <a target='_blank' href='http://office.com/webapps'>Office Online</a>.</iframe>
如果您只想显示内容,那么您可以将word文件转换为pdf文件类型。您可以使用 cloud convert 将文件从一种格式转换为另一种格式。目前云转换支持多达 128 种不同的文件格式。
关于javascript - 如何在本地主机的浏览器中显示word文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35788746/