How do I add a custom script on a specific page? I wanted to add custom JavaScript code on certain nodes.
I have written this code in the html.tpl.php template, but this doesn't work. (donate is the path alias for a node.)
&lt;?php if(arg(0) == 'DONATE'): ?&gt;
  &lt;script&gt;
    (function() {
      // ...
    );
  &lt;/script&gt;
&lt;?php endif; ?&gt;
You could do this:

&lt;?php
$node = menu_get_object();
if ($node &amp;&amp; $node-&gt;nid == DONATE_NODE_ID):
?&gt;
&lt;script&gt;&lt;/script&gt;
&lt;?php endif; ?&gt;


But a better way would be to:


Wrap your script in Drupal.behaviors:

(function ($) {
  Drupal.behaviors.NameOfYourTheme = {
    attach: function (context, settings) {
      // Your JS code goes here.
    }
  }
})(jQuery);

Call drupal_add_js() in hook_preprocess_page(). This code would go to template.php:

function YOUR_THEME_preprocess_page(&amp;$variables) {
  $node = menu_get_object();
  if ($node &amp;&amp; $node-&gt;nid == DONATE_NODE_ID) {
    drupal_add_js(drupal_get_path('theme', 'YOUR_THEME') . '/path/to/js.js');
  }
}