/** * 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标签 会引发异常