var loadCSS = function(url, callback){ var link = document.createElement('link'); link.type = 'text/css'; link.rel = 'stylesheet'; link.href = url; document.getElementsByTagName('head')[0].appendChild(link); var img = document.createElement('img'); img.onerror = function(){ (callback) ? callback(link) : alert('style sheet loaded!'); } img.src = url; } var input = document.getElementById('cssinput'); input.addEventListener('keypress', function(e){ if(e.keyCode && e.keyCode == 13) loadCSS(input.value); }, false);
<span>Type in a CSS file's location and hit enter to load it:</span> <input id="cssinput" type="text" style="width: 100%;" value="http://www.backalleycoder.com/big-css-file.css" />