New Idea of associating module ID with factory

Source: Internet
Author: User

This is an hack that leverages the jquery team to add HTML5 new tags to the IE6-8!

 
Function createsafefragment (document) {var list = nodenames. split ("|"), safefrag = document. createdocumentfragment (); If (safefrag. createelement) {While (list. length) {safefrag. createelement (list. pop () ;}} return safefrag ;}

However, after ie9, there will be no createelement Method for document fragments. But we can change it to document. createelement ("script.

However, after ie10, if the file fragment is not inserted into the DOM tree, no request will be sent, which is consistent with the behavior of other standard browsers. Therefore, it is a war of consumption to fight against the browser. People can continue to upgrade and kill your heack flash.

The problem with IE is that the first parse is not necessarily the first onload, and the early onload of IE is simulated by onreadystatechange. In addition, IE6 also enjoys base tags, which forces us to insert (insertbefore) in reverse order ).

 var frag = document. createdocumentfragment () var script = frag. createelement ('script') frag. moduleid = "Lang" script. onreadystatechange = function () {console. log (this. parentnode. nodetype); // 11 console. log (this. parentnode. moduleid); // Lang // obtain the module ID, and then associate it with Lang. the factory in JS is bound together with document. getelementsbytagname ("head") [0]. appendchild (frag)} script. src = 'lang. js'; frag. appendchild (SCRIPT) 

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.