我在ie7/8中将脚本附加到头部时遇到问题
这是我正在使用的代码
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);
这是我得到的错误
SCRIPT5007: Unable to get value of the property
'appendChild': object is null or undefined
我找到了这个createElement error in IE8并尝试更新我的代码
var appendChild = document.head.appendChild(requireTag);
但是仍然会得到相同的错误。有人能帮上忙吗?
发布于 2013-06-14 10:36:24
根据https://developer.mozilla.org/en-US/docs/Web/API/document.head和http://msdn.microsoft.com/en-us/library/gg593004%28v=vs.85%29.aspx的说法,document.head
不适用于IE<9。
document.getElementsByTagName('head')[0].appendChild(requireTag);
发布于 2013-06-14 10:35:26
我相信这些浏览器不支持document.head
。
试着这样做:
var head = document.getElementsByTagName("head")[0];
head.appendChild(requireTag);
https://stackoverflow.com/questions/17100246
复制相似问题