Skip to content

Instantly share code, notes, and snippets.

@davidbarredo
Created November 19, 2013 12:35
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 davidbarredo/7544705 to your computer and use it in GitHub Desktop.
Save davidbarredo/7544705 to your computer and use it in GitHub Desktop.
Dynamically add a script of a github gist
/* Create script element */
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://gist.github.com/7544705.js';
/* Backup document.write function */
if(!document._write) document._write = document.write;
/* Override document.write function */
document.write = function (str) {
document.getElementById('scriptCont').innerHTML += str;
};
/* Append the script element to #scriptCont */
document.getElementById('scriptCont').appendChild(script);
/* When the script load, restore the document.write function */
script.onload = function () {
setTimeout(function(){
document.write = document._write;
},0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment