The globalEval()
method is used internally by jQuery to evaluates scripts in a global context. It's been inspired by
a post of Andrea Giammarchi. It is as follows:
// Evalulates a script in a global context globalEval: function( data ) { if ( data && rnotwhite.test(data) ) { // Inspired by code by Andrea Giammarchi // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html var head = document.getElementsByTagName("head")[0] || document.documentElement, script = document.createElement("script"); script.type = "text/javascript"; if ( jQuery.support.scriptEval ) { script.appendChild( document.createTextNode( data ) ); } else { script.text = data; } // Use insertBefore instead of appendChild to circumvent an IE6 bug. // This arises when a base node is used (#2709). head.insertBefore( script, head.firstChild ); head.removeChild( script ); } },
- creates a
script
element through the W3C DOMcreateElement
method - appends the newly created script to the
head
element by using the W3C DOMinsertBefore
instead ofappendChild
to circumvent an IE6 bug.