(Tutorial) Add JavaScript to Drupal 6 for the front page only
Tips : Add JavaScript to Drupal 6 for the front page only
his cropped up in the Drupal forums today, again, so I dug this bit of code out since I was messing about with recently. If you want to load a .js file only for the homepage there's a couple of ways of doing it.
First in template.php you can simply add the following - which assumes you have saved the .js file in your theme folder. Adjust the path to suit (for example /js/myscript.js).
if (drupal_is_front_page()) {
drupal_add_js(drupal_get_path('theme', 'mytheme').'/myscript.js', 'theme');
}This is nice since you can add a few more parameters to it - see the full story here http://api.drupal.org/api/function/drupal_add_js
Courtesy : Adaptivethemes.com
- guru's blog
- Login to post comments

![Drupal-6-Book-[Building Powerful and Robust Websites with Drupal 6].jpg](http://www.drupalranch.com/images/Drupal-6-Book-[Building%20Powerful%20and%20Robust%20Websites%20with%20Drupal%206].jpg)