| Versions | |
|---|---|
| 4.7 | drupal_call_js($function) |
Generates a Javascript call, while importing the arguments as is. PHP arrays are turned into JS objects to preserve keys. This means the array keys must conform to JS's member naming rules.
$function The name of the function to call.
$arguments An array of arguments.
includes/
<?php
function drupal_call_js($function) {
$arguments = func_get_args();
array_shift($arguments);
$args = array();
foreach ($arguments as $arg) {
$args[] = drupal_to_js($arg);
}
$output = '<script type="text/javascript">' . $function . '(' . implode(', ', $args) . ');</script>';
return $output;
}
?>