Adding Javascript in Drupal

Examples of how to add javascript in your Drupal sites :

<?php
  // This will add a JS file to your head (specifically the $scripts variable in page.tpl.php)
  drupal_add_js(drupal_get_path('module', 'my_module') . '/my_module.js');

  // This add inline JS to the head of the document
  drupal_add_js('alert("Hello!")', 'inline');

  // This will add variables in the Drupal.settings object
  drupal_add_js(array('my_module' => array('my_setting' => 'this_value')), 'setting');

?>

http://www.innovatingtomorrow.net/2008/06/02/jquery-and-drupal

http://www.nicklewis.org/drupal-hackers-cookbook/jquery-js/unlocking-dru...




Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
Bg