jQuery 如何使用fancybox显示word文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9418850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to display a word document using fancybox
提问by dude
HTML code
HTML代码
<div class='case'>
<a href="http://localhost/DXXX/case/reqirement.doc" rel="case"> view</a>
</div>
Jquery code
查询代码
$(".case").live('click', function(){
$.fancybox({
openEffect: 'elastic',
closeEffect: 'elastic'
});
});
it's displays the requested content cannot be loaded please try again later.... And I get a download of that document file... How can I display the document file using fancybox
它显示无法加载请求的内容,请稍后再试....我得到了该文档文件的下载...如何使用fancybox显示文档文件
回答by JFK
UPDATE: Jan 29, 2017
更新:2017 年 1 月 29 日
Google Docs Viewer allows the Word document to be seen as a (read-only) document rather than an image (as it was previously working), so you can actually select and copy from the displayed document into another document.
Google Docs Viewer 允许将 Word 文档视为(只读)文档而不是图像(因为它以前是有效的),因此您实际上可以从显示的文档中选择并复制到另一个文档中。
Added a JSFIDDLEusing Fancybox v2.1.5
增加了一个的jsfiddle使用的fancybox v2.1.5
The only possible way to do it without all the issues mentioned above is to use Google docs viewer to display the image of the file via iframe ...so this script:
在没有上述所有问题的情况下,唯一可能的方法是使用 Google 文档查看器通过 iframe 显示文件的图像……所以这个脚本:
$(document).ready(function() {
$(".word").fancybox({
'width': 600, // or whatever
'height': 320,
'type': 'iframe'
});
}); // ready
with this html:
使用这个 html:
<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>
... should do the trick.
......应该可以解决问题。
Just notice that you are not actually opening a Word document but an image of it, which will work if what you want is to show the content of the document only.
请注意,您实际上并没有打开 Word 文档,而是打开了它的图像,如果您只想显示文档的内容,这将起作用。
BTW, I noticed that you must be using fancybox v2.x. In that case you don't need the .live()
method at all since fancyBox v2 already uses "live" to handle clicks.
顺便说一句,我注意到你必须使用fancybox v2.x。在这种情况下,您根本不需要该.live()
方法,因为fancyBox v2 已经使用“live”来处理点击。
回答by j08691
You can't. Browsers don't have any built-in way to view Word docs so unless the user has configured their browser to open it with some plugin (which 99% of the world hasn't done), the browser will prompt them to download the file.
你不能。浏览器没有任何内置方式来查看 Word 文档,因此除非用户将浏览器配置为使用某些插件打开它(世界上 99% 的人都没有这样做),否则浏览器会提示他们下载文件.
回答by Jovan Perovic
As far as I know you will need some sort of plugin that will know how to handle that MIME type. Other than that it is not possible.
据我所知,您将需要某种插件来知道如何处理该 MIME 类型。除此之外是不可能的。
Same goes for any file type...
任何文件类型都一样......
回答by zookastos
You can use this code, short and sweet (with Fancybox latest version) -
您可以使用此代码,简短而甜蜜(使用 Fancybox 最新版本)-
$.fancybox.open({
padding: 0,
href: $url,
type: 'iframe',
});
Where your $url can be something like -
你的 $url 可以是这样的 -
https://docs.google.com/viewer?url=<url for your file>&embedded=true