Drupal – adding your JavaScript at desired position and on specific page

In Drupal, sometime you use the JavaScript file that is needed to specific page. Drupal provide the way to do this by using the drupal_add_js() method. This method takes various parameters which help you to decide the order, group, scope etc. of this added JavaScript file. Here is the example.

function mytheme_preprocess_node(&$vars) {

  if ($vars['node']->nid == 7) {
    $theme_path = drupal_get_path('theme', 'mytheme');
    drupal_add_js($theme_path . '/js/ClubFinder.js',array('weight' => 55,'group'=>100));
  }
}

 

Tags