jQuery.globalEval()

jQuery

jQuery.globalEval()


jQuery.globalEval( code ) Returns:

Description: Execute some JavaScript code globally.

  • version added: 1.0.4jQuery.globalEval( code )

    • code
      Type: String
      The JavaScript code to execute.

This method behaves differently from using a normal JavaScript eval() in that it's executed within the global context (which is important for loading external scripts dynamically).

Example:

Execute a script in the global context.

1
2
3
4
5
                                  
function test(){
jQuery.globalEval("var newVar = true;")
}
test();
// newVar === true