While that may have been the best answer at the time, I believe there's now a better one.
For a given gist, e.g. https://gist.github.com/anonymous/5446951, you can access a JSON object containing the HTML markup and CSS URI for the Gist at https://gist.github.com/anonymous/5446989.json - it looks something like:
{
"description": ...,
"public":true,
...
"div": <HTML code>,
"stylesheet": <URI of CSS file>
}
In fact, you can get this data as JSONP: https://gist.github.com/anonymous/5446989.json?callback=callback12345
So, to dynamically load a Gist without an iframe:
function loadGist(element, gistId) {
var callbackName = "gist_callback";
window[callbackName] = function (gistData) {
delete window[callbackName];
var html = '<link rel="stylesheet" href="' + escapeHtml(gistData.stylesheet) + '"></link>';
html += gistData.div;
element.innerHTML = html;
script.parentNode.removeChild(script);
};
var script = document.createElement("script");
script.setAttribute("src", "https://gist.github.com/" + gistId + ".json?callback=" + callbackName);
document.body.appendChild(script);
}