jQuery in Action
Dynamically loading scripts
183
parameter to the
$.getScript()
function. This callback executes the
click
han-
dler for the Inspect button, calling the dynamically loaded function with the
loaded variable as its parameter.
loaded variable as its parameter.
In browsers other than Safari, the function and variable loaded dynamically
from the script are available within the callback function. But when executed on
Safari, nothing happens! We need to take heed of this divergence of functionality
when using the
Safari, nothing happens! We need to take heed of this divergence of functionality
when using the
$.getScript()
function.
Figure 6.6 The dynamic loading and evaluation of the script file results in the inline
alert statement being executed.
alert statement being executed.
Figure 6.7 The appearance of the alert shows that the dynamic function is loaded
correctly, and the correctly displayed value shows that the variable was
dynamically loaded.
correctly, and the correctly displayed value shows that the variable was
dynamically loaded.