Hello fellow JavaScripters, here is some code that I am working on to load styles into a page depending on the protocol of the URL. It seems to load the .css files correctly in FF but in IE I get an “document.head is null or not an object” error. was wondering if I cold get any assistance.
You are opening a window.onload function but not closing it; you need a brace and a semicolon on that last line. FireFox and other modern browsers are more forgiving then IE and will sometimes overlook simple errors like this.
Optimized code:
window.onload = function() {
var protocol = document.location.protocol;
var ref = document.createElement('link');
ref.setAttribute('rel', 'stylesheet');
ref.setAttribute('type', 'text/css');
if (protocol == 'http:') {
ref.setAttribute('href', 'IE.css');
} else if (protocol == 'https:') {
ref.setAttribute('href', 'IEhttps.css');
}
document.head.appendChild(ref);
};
Just wanted to thank everyone for there help, I am able to get it to work by. The problem is it now takes almost a minute to apply the style to the page. here is the finishing code.