Insert the script file dynamically into the head with the following code:
var sc = document.createelement ("script"= "//www.chinanews.com/ie8/js/json2.min.js"; var head = document.getElementsByTagName ("head") [0];head.appendchild (SC);
But the following code to insert is as follows:
<!--[if Lt IE 9]> <script src= "/ie8/js/json2.min.js" > </script><![ Endif]-->
The innerHTML attribute of the HTML DOM is used to put the above code in a string and into the head
var jsonstr = ' <!--[if LT IE 9]><script src= "/ie8/js/json2.min.js" ></script><! [endif]--> '; var head = document.getElementsByTagName ("Head") [0];head.innerhtml = head.innerhtml + jsonstr;
Gets the characters from the previous head and adds a new string, but in IE, the InnerHTML property cannot be set. The target component for this operation is invalid "error.
http://w3help.org/zh-cn/causes/BX9046
Finally, by judging whether the browser is IE and version, add JS file dynamically
if ((Navigator.userAgent.indexOf (' MSIE ') >= 0) && (navigator.userAgent.indexOf (' Opera ') < 0)) {// determine if it is IE browser if (Isiever (7) | | isiever (8) | | isiever (6)) { = document.createelement ("script"); = "/ie8/js/json2.min.js"; Head.appendchild (Json2); }}
http://blog.csdn.net/smilepi/article/details/21076097
Use the InnerHTML property to insert the character times into the head "the InnerHTML property cannot be set. The target component for this operation is invalid "error