Skip to content

Instantly share code, notes, and snippets.

@BrentFarris
Last active August 29, 2015 14:13
Show Gist options
  • Save BrentFarris/a1c2a1156bb78a692289 to your computer and use it in GitHub Desktop.
Save BrentFarris/a1c2a1156bb78a692289 to your computer and use it in GitHub Desktop.
Gist iFrame With Working Links
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Dynamic Gist Embedding</title>
</head>
<body>
<div id="gistZone"></div>
<script type="text/javascript">
function LoadGist(id) {
if (id) {
// Create an iframe, append it to this document where specified
var gistFrame = document.createElement("iframe");
gistFrame.setAttribute("width", "100%");
gistFrame.id = "gistFrame";
var zone = document.getElementById("gistZone");
zone.innerHTML = "";
zone.appendChild(gistFrame);
// Create the iframe's document
var gistFrameHTML = '<html><body onload="parent.adjustIframeSize(document.body.scrollHeight)"><scr' + 'ipt type="text/javascript" src="https://gist.github.com/' + id + '.js"></sc'+'ript><base target="_parent" /></body></html>';
// Set iframe's document with a trigger for this document to adjust the height
var gistFrameDoc = gistFrame.document;
if (gistFrame.contentDocument) {
gistFrameDoc = gistFrame.contentDocument;
} else if (gistFrame.contentWindow) {
gistFrameDoc = gistFrame.contentWindow.document;
}
gistFrameDoc.open();
gistFrameDoc.writeln(gistFrameHTML);
gistFrameDoc.close();
}
}
function adjustIframeSize(newHeight) {
var i = document.getElementById("gistFrame");
i.style.height = parseInt(newHeight) + "px";
}
LoadGist("a1c2a1156bb78a692289");
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment