function drupal_add_js

You are here

7 common.inc drupal_add_js($data = NULL, $options = NULL)
4.7 common.inc drupal_add_js($file, $nocache = FALSE)
5 common.inc drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE)
6 common.inc drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer = FALSE, $cache = TRUE, $preprocess = TRUE)

Add a JavaScript file to the output.

The first time this function is invoked per page request, it adds "misc/drupal.js" to the output. Other scripts depends on the 'killswitch' inside it.

Related topics

6 calls to drupal_add_js()
theme_fieldset in includes/form.inc
Format a group of form items.
theme_textarea in includes/form.inc
Format a textarea.
theme_textfield in includes/form.inc
Format a textfield.
update_progress_page in ./update.php
update_selection_page in ./update.php

... See full list

File

includes/common.inc, line 1248
Common functions that many Drupal modules will need to reference.

Code

function drupal_add_js($file, $nocache = FALSE) {
  static $sent = array();

  $postfix = $nocache ? '?' . time() : '';
  if (!isset($sent['misc/drupal.js'])) {
    drupal_set_html_head('<script type="text/javascript" src="' . base_path() . 'misc/drupal.js' . $postfix . '"></script>');
    $sent['misc/drupal.js'] = true;
  }
  if (!isset($sent[$file])) {
    drupal_set_html_head('<script type="text/javascript" src="' . check_url(base_path() . $file) . $postfix . '"></script>');
    $sent[$file] = true;
  }
}