Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  136] [ 2]  / answers: 1 / hits: 19261  / 11 Years ago, fri, june 14, 2013, 12:00:00

i am having an issue appending a script to the head in ie7/8



this is the code i am using



var requireTag = document.createElement('script');
requireTag.setAttribute('type', 'text/javascript');
requireTag.setAttribute('src', link+ 'require.js');
requireTag.setAttribute('data-main', link+ 'data');

document.head.appendChild(requireTag);


this is the error i get



SCRIPT5007: Unable to get value of the property
'appendChild': object is null or undefined


I found this createElement error in IE8 and tried updating my code to have



var appendChild = document.head.appendChild(requireTag);


but still get the same error. Can anyone help?


More From » appendchild

 Answers
44

According to https://developer.mozilla.org/en-US/docs/Web/API/document.head and http://msdn.microsoft.com/en-us/library/gg593004%28v=vs.85%29.aspx , document.head isn't available to IE<9. Just use



document.getElementsByTagName('head')[0].appendChild(requireTag);

[#77629] Wednesday, June 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
catrinas

Total Points: 587
Total Questions: 100
Total Answers: 105

Location: Rwanda
Member since Thu, Feb 10, 2022
2 Years ago
;