Skip to content

Instantly share code, notes, and snippets.

@barryvdh
Created April 24, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryvdh/3ea0393a27f4137f42f9e1f2a0af9b64 to your computer and use it in GitHub Desktop.
Save barryvdh/3ea0393a27f4137f42f9e1f2a0af9b64 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Google Doc viewer</title>
<style type="text/css">
body, html {
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
#content {
position:absolute; left: 0; right: 0; bottom: 0; top: 0;
}
</style>
</head>
<body>
<div id="content">
<iframe id="embed" width="100%" height="100%" frameborder="0"></iframe>
</div>
<script>
/**
* Helper function to parse query string (e.g. ?param1=value&parm2=...).
*/
function parseQueryString(query) {
var parts = query.split('&');
var params = {};
for (var i = 0, ii = parts.length; i < ii; ++i) {
var param = parts[i].split('=');
var key = param[0].toLowerCase();
var value = param.length > 1 ? param[1] : null;
params[decodeURIComponent(key)] = decodeURIComponent(value);
}
return params;
}
window.onload = function() {
var queryString = document.location.search.substring(1);
var params = parseQueryString(queryString);
var embedUrl = 'https://docs.google.com/gview?embedded=true&url=' + encodeURIComponent(params.url);
var iframe = document.getElementById("embed");
document.getElementById("embed").src = embedUrl;
var checkLocation = setInterval(function(){
try {
if (iframe.contentWindow.location.toString() === 'about:blank') {
iframe.contentWindow.location = embedUrl;
return; // Return to try again later
}
} catch (e) {
//console.log(e);
}
clearInterval(checkLocation);
}, 1000);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment