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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.