javascript – 如何在localhost中的浏览器中显示word文档?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 如何在localhost中的浏览器中显示word文档?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1894字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 如何在localhost中的浏览器中显示word文档?](/upload/InfoBanner/zyjiaocheng/761/d4d6426979f64047afc02a597cddbcd2.jpg)
我从stackoverflow获得了这个代码,它可以在浏览器中显示word文档.是否可以在localhost中显示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');
?>
您可以使用办公室实时应用查看器,需要互联网连接://view.officeapps.live.com/op/embed.aspx?src=your_url_here
把这个网址放在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种不同的文件格式.
还有另一个SO link for file format conversion
内容总结
以上是互联网集市为您收集整理的javascript – 如何在localhost中的浏览器中显示word文档?全部内容,希望文章能够帮你解决javascript – 如何在localhost中的浏览器中显示word文档?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。