First inside custom module, create an array to be passed to Drupal.settings.
<?php // Assiging the value to a variable $variable_name = 'value'; $settings_name = array ( 'my_custom_settings' => $variable_name, ); // Call to drupal_add_js and the parameters are our custom settings as array, and second is 'settings' itself. drupal_add_js(array('custom_settings' => $settings_name), 'setting'); ?>
So we have created our custom settings and the variable in our custom settings array will be available in js. We can access this value in js file like this.
var customVariable = Drupal.settings.custom_settings.my_custom_settings;
Hope this helps.