Skip to content

Instantly share code, notes, and snippets.

@javajack
Created December 10, 2013 19:18
Show Gist options
  • Save javajack/7896449 to your computer and use it in GitHub Desktop.
Save javajack/7896449 to your computer and use it in GitHub Desktop.
A JQuery Plugin for Google Doc Viewer Iframe Embeding http://jsfiddle.net/javajack/4s8bn/embedded/result/
/*
* jQuery.gdocViewer - Embed linked documents using Google Docs Viewer
* Licensed under MIT license.
* Date: 2011/01/16
*
* @author Jawish Hameed
* @version 1.0
*/
(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|pdf|ppt|pps|doc|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 );
$(document).ready(function() {
$('a.embed').gdocsViewer({width: 740, height: 742});
$('#embedURL').gdocsViewer();
});
<a href="www.snee.com/xml/xslt/sample.doc" class="embed" style="text-align : center; display : block;">PDF test georgetown.edu</a>
@jitupatel76877
Copy link

pdf viewer is working find but i set doc in my local directory doc is download not open in iframe

@jitupatel76877
Copy link

please helf me

Copy link

ghost commented Nov 26, 2019

please helf me
Google Doc Viewer can only view documents uploaded on server or drive. It will use document URL.

Copy link

ghost commented Nov 26, 2019

@javajack is it possible to remove pop-out option in google document viewer ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment