Asynchronously load scripts and styles

Source: Internet
Author: User

<SCRIPT> window. onload = function () {loadscripturl ('script/head. JS ') loadscriptcode ('alert ("HAHAHA");'); loadstyleurl('a.css '); var csscode =' # box {Background: Red} '; loadstylecode (csscode );} function loadscripturl (URL) {var script = document. createelement ("script"); script. src = URL; script. type = "text/JavaScript"; document. getelementsbytagname ('head') [0]. appendchild (SCRIPT);} function loadscriptcode (CODE) {var script = document. createelement ("script"); script. type = "text/JavaScript"; script. TEXT = Code; document. getelementsbytagname ('head') [0]. appendchild (SCRIPT);} function loadstyleurl (URL) {var link = document. createelement ('link'); Link. rel = 'stylesheet '; Link. href = 'text/CSS '; Link. href = URL; document. getelementsbytagname ('head') [0]. appendchild (Link);} function loadstylecode (CODE) {var style = document. createelement ('style'); style. type = 'text/CSS '; var box = document. createtextnode (CODE); // style is not supported in earlier ie versions. appendchild (box); document. getelementsbytagname ('head') [0]. appendchild (style) ;}</SCRIPT>


This article from the "Sky sea wide" blog, please be sure to keep this source http://ether007.blog.51cto.com/8912105/1435065

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.