如何使用JavaScript在浏览器中呈现Word文档(.doc,.docx)? [英] How do I render a Word document (.doc, .docx) in the browser using JavaScript?
问题描述
我已成功完成代码以在浏览器中显示PDF文件,而不是打开/保存对话框。现在,我一直试图在浏览器中显示Word文档。我想在Firefox,IE7 +,Chrome等中显示Word文档。
I have successfully done code to display a PDF file in the browser instead of the "Open/Save" dialog. Now, I'm stuck trying to display a Word document in the browser. I want to display a Word document in Firefox, IE7+, Chrome etc.
任何人都可以帮忙吗?在浏览器中显示Word文档时,我总是收到打开/保存对话框。我想使用JavaScript实现此功能。
Can any one help? I am always getting the "Open/Save" dialog while displaying the Word doc in browser. I want to implement this functionality using JavaScript.
推荐答案
目前没有任何浏览器具有呈现Word文档所需的代码,并且我知道,目前还没有用于呈现它们的客户端库。
No browsers currently have the code necessary to render Word Documents, and as far as I know, there are no client-side libraries that currently exist for rendering them either.
但是,如果您只需要显示Word文档,但不需要要编辑它,您可以通过< iframe>
使用Google文档查看器来显示远程托管的 .doc
/ .docx
。
However, if you only need to display the Word Document, but don't need to edit it, you can use Google Documents' Viewer via an <iframe>
to display a remotely hosted .doc
/.docx
.
<iframe src="https://docs.google.com/gview?url=http://remote.url.tld/path/to/document.doc&embedded=true"></iframe>
解决方案改编自如何显示单词文档>。
Solution adapted from "How to display a word document using fancybox".
示例:
但是,如果您更喜欢本机支持,在大多数情况下,如果不是所有浏览器,我建议重新保存 .doc
/ .docx
作为PDF文件也可以使用 PDF格式独立呈现。来自Mozilla的js 。
However, if you'd rather have native support, in most, if not all browsers, I'd recommend resaving the .doc
/.docx
as a PDF file Those can also be independently rendered using PDF.js by Mozilla.
编辑:
非常感谢 fatbotdesigns ,用于在评论中发布Microsoft Office 365查看器。
Huge thanks to fatbotdesigns for posting the Microsoft Office 365 viewer in the comments.
<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>
要记住一个更重要的警告,正如lightswitch05 ,这会将您的文档上传到第三方服务器。如果这是不可接受的,那么这种显示方式不是正确的行动方式。
One more important caveat to keep in mind, as pointed out by lightswitch05, is that this will upload your document to a third-party server. If this is unacceptable, then this method of display isn't the proper course of action.
实例:
这篇关于如何使用JavaScript在浏览器中呈现Word文档(.doc,.docx)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!