How do I render a Word document (.doc, .docx) in the browser using JavaScript?

后端 未结 10 1026
难免孤独
难免孤独 2020-11-22 07:32

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 w

10条回答
  •  感动是毒
    2020-11-22 08:15

    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.

    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

    Solution adapted from "How to display a word document using fancybox".

    Example:

    JSFiddle

    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.

    Edit:

    Huge thanks to fatbotdesigns for posting the Microsoft Office 365 viewer in the comments.

    
    

    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.

    Live Examples:

    Google Docs Viewer

    Microsoft Office Viewer

提交回复
热议问题