`
sohighthesky
  • 浏览: 34779 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

why insertBefore not appendChild?

阅读更多
        /**
         * Evalulates a script in a global context.
         */
        globalEval: function(data) {
            if (data && REG_NOT_WHITE.test(data)) {
                // Inspired by code by Andrea Giammarchi
                // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html
                var head = doc.getElementsByTagName('head')[0] || doc.documentElement,
                    script = doc.createElement('script');

                // It works! All browsers support!
                script.text = data;

                // Use insertBefore instead of appendChild to circumvent an IE6 bug.
                // This arises when a base node is used.
                head.insertBefore(script, head.firstChild);
                head.removeChild(script);
            }
        }
    });

经常看大家使用insertBefore,而不用appendChild
:
LC(============================) 12:23:42
两个BUG
1。 head没加载完毕 会报未运行是异常
2。 如果head部分有base标签 会引发异常
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics