I have my code to embed files in page and open in Google Docs Viewer. but so far I get "No preview available" when i want to open .doc or docx files but opens correctly when I open PDF files. And again instead of opening the file in Google Docs I'm prompted to download the file instead of viewing it on the browser.
Here is my code:
<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>
And here is my jQuery plugin:
(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 );