Skip to content

Instantly share code, notes, and snippets.

@lackneets
Last active August 29, 2015 14:02
Show Gist options
  • Save lackneets/008501a1cc4e3962dc60 to your computer and use it in GitHub Desktop.
Save lackneets/008501a1cc4e3962dc60 to your computer and use it in GitHub Desktop.
insertScripts in console
(function insertScripts(src) {
if (src instanceof Array && src.length) {
insertScripts(src.shift())
return insertScripts(src);
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
document.head.appendChild(script);
})([
'//code.jquery.com/jquery-1.11.0.min.js',
'//code.jquery.com/jquery-migrate-1.2.1.min.js'
]);
(function loadGoogleMap(callback) {
if ((typeof google != 'undefined') && google.maps && google.maps.version) {return callback && callback();}
var callbackName = ['google_map_initialize', new Date().getTime()].join('_')
window[callbackName] = callback || function() {};
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&callback=' + callbackName;
document.body.appendChild(script);
})(function() {
// initialize here
console.log('Google Map loaded')
});
function loadjscssfile(filename, filetype) {
if (filetype == "js") { //if filename is a external JavaScript file
var fileref = document.createElement('script')
fileref.setAttribute("type", "text/javascript")
fileref.setAttribute("src", filename)
} else if (filetype == "css") { //if filename is an external CSS file
if (document.createStyleSheet) { //IE8 ONLY
document.createStyleSheet(filename);
} else {
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
}
if (typeof fileref != "undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
loadjscssfile("myscript.js", "js") //dynamically load and add this .js file
loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment