I have a script running in the head of my html document and it works in every browser except for internet explorer. Tested in Opera, Safari, Chrome, Firefox, Internet Explorer.
My code is as follows:
<html>
<head>
<script type = "text/javascript">
var date = new Date();
var month = date.getMonth() + 1;
if (month >= 3 && month <= 5)
{
var NewScript = document.createElement("script");
NewScript.type = "text/javascript";
NewScript.src = "source1.js";
var NewStyles = document.createElement("link");
NewStyles.rel = "stylesheet";
NewStyles.type = "text/css";
NewStyles.href = "css1.css";
document.head.appendChild(NewScript);
document.head.appendChild(NewStyles);
}
else
{
var NewScript = document.createElement("script");
NewScript.type = "text/javascript";
NewScript.src = "source2.js";
var NewStyles = document.createElement("link");
NewStyles.rel = "stylesheet";
NewStyles.type = "text/css";
NewStyles.href = "css2.css";
document.head.appendChild(NewScript);
document.head.appendChild(NewStyles);
}
</script>
</head>
<body>
<!-- MY CONTENT GOES HERE -->
</body>
</html>
I'm not sure if it's the document.createElement or document.head.appendChild that isn't working in IE. As stated before, it works in all other browsers that I've tested it in. Help with this would be greatly appreciated as I will continue to find the problem / solution myself. Thanks!
Try document.getElementsByTagName('head')[0]
instead of document.head
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With