【发布时间】:2019-06-11 16:01:44
【问题描述】:
我有将文件嵌入页面并在 Google Docs Viewer 中打开的代码。但到目前为止,当我想打开 .doc 或 docx 文件但打开 PDF 文件时正确打开时,我得到“没有可用的预览”。 再次提示我下载文件而不是在浏览器上查看文件,而不是在 Google Docs 中打开文件。
这是我的代码:
<a href="sample.doc" class="embed"><h2>sample.doc</h2><button >view document</button></a>
<script>
$(document).ready(function() {
$('a.embed').gdocsViewer({width:740,height:742});
$('#embedURL').gdocsViewer();
});
</script>
这是我的 jQuery 插件:
(function($){
$.fn.gdocsViewer = function(options) {
var settings = {
width : '600',
height : '700'
};
if (options) {
$.extend(settings, options);
}
return this.each(function() {
var file = $(this).attr('href');
var ext = file.substring(file.lastIndexOf('.') + 1);
if (/^(tiff|doc|ppt|pps|pdf|docx)$/.test(ext)) {
$(this).after(function () {
var id = $(this).attr('id');
var gdvId = (typeof id !== 'undefined' && id !== false) ? id + '-gdocsviewer' : '';
return '<div id="' + gdvId + '" class="gdocsviewer"><iframe src="http://docs.google.com/viewer?embedded=true&url=' + encodeURIComponent(file) + '" width="' + settings.width + '" height="' + settings.height + '" style="border: none;margin : 0 auto; display : block;"></iframe></div>';
})
}
});
};})( jQuery );
【问题讨论】:
标签: php jquery google-docs-api