Enable innerHTML scripts to run. _ javascript skills

Source: Internet
Author: User
This allows innerHTML scripts to run. Recently, I 've been thinking about pjblog refactoring. of course, you must think about all the things you need to do before refactoring. one of them comes up with a js improvement. The innerHTML script can also be run. but I tried it. the innerHTML script cannot be executed in IE. I tried several times and found that there are other objects in the inserted HTML before script and defer is set in the script. Such a script innerHTML is executed by IE ., however, this trick is ineffective for firefox ~~ Later, I found some information and found that firefox can re-append the object or insertBefore to execute the script.

Program code
Var fillHTML = function (el, HTMLString ){
If (! El) return;
If (window. ActiveXObject) {// For IE
El. innerHTML = "" + HTMLString. replace (/ ] *)>/Ig ,' ');
El. removeChild (el. firstChild)
} Else {// For Mozilla, Opare
Var nSibling = el. nextSibling;
Var pNode = el. parentNode;
PNode. removeChild (el );
El. innerHTML = HTMLString;
PNode. insertBefore (el, nSibling)
}
}

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.