Skip to content

Instantly share code, notes, and snippets.

@calderonsteven
Created November 7, 2012 02:07
Show Gist options
  • Select an option

  • Save calderonsteven/4029163 to your computer and use it in GitHub Desktop.

Select an option

Save calderonsteven/4029163 to your computer and use it in GitHub Desktop.
inject css and js via javascript
function includeCSSfile(href) {
var head_node = document.getElementsByTagName('head')[0];
var link_tag = document.createElement('link');
link_tag.setAttribute('rel', 'stylesheet');
link_tag.setAttribute('type', 'text/css');
link_tag.setAttribute('href', href);
head_node.appendChild(link_tag);
}
function includeJavascript(src) {
if (document.createElement && document.getElementsByTagName) {
var head_tag = document.getElementsByTagName('head')[0];
var script_tag = document.createElement('script');
script_tag.setAttribute('type', 'text/javascript');
script_tag.setAttribute('src', src);
head_tag.appendChild(script_tag);
}
}
// Include javascript src file
includeJavascript("http://www.mydomain.com/script/mynewscript.js");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment