execScript method (window)
Executes the specified script in the specified language.
This method can be useful if you want to execute a script written in another scripting language from JavaScript,
but it can also be useful when you have a JavaScript code as a string.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. String that specifies the code to be executed. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Required. String that specifies the scripting language. This parameter is not case sensitive.
One of the following values:
|
Return value:
Always returns null.
Example HTML code 1:
This example illustrates the use of the execScript method:
|
||||
<head> <script type="text/javascript"> var jsCode = "alert ('Execution is completed.');"; if (window.execScript) { // Internet Explorer and Google Chrome execScript (jsCode, "JavaScript"); } else { if (window.eval) { // the script language is always JavaScript for the eval method eval (jsCode); } } </script> </head> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example is the same as the previous one, but is uses the cross-browser Function object to execute a string of JavaScript code:
|
||||
<head> <script type="text/javascript"> var jsCode = "alert ('Execution is completed.');"; (new Function (jsCode)) (); </script> </head> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments