The document.head in JavaScript is not compatible with IE below.

Source: Internet
Author: User

var url = URL address;   var _script = document.createelement (' script ');   _script.type = "Text/javascript";   _script.src = URL; Document.head.appendChild (_script);

The use of Ajax requests can not cross-domain, so find this string of code, can cross-domain, in Google Firefox above all measured, no problem, the program is all right, but in IE, there is a problem, prompting the code error,

Document.head.appendChild (Element) head is empty.


Change the document.head above to

var head = document.getElementsByTagName ("Head") [0];head.appendchild (Requiretag);

This will be OK. Compatible with all browsers.

----------------------------------------------------------------------------

The following is the code I found from the Internet, no test, I do not know whether to use, the back of the test

var Requiretag = document.createelement (' script '); Requiretag.setattribute (' type ', ' text/javascript '); requiretag.se Tattribute (' src ', link+ ' require.js '), Requiretag.setattribute (' Data-main ', link+ ' data ');d Ocument.head.appendC Hild (Requiretag);

This article is from the "Music" blog, be sure to keep this source http://boysmusic.blog.51cto.com/9398683/1758458

The document.head in JavaScript is not compatible with IE below.

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.