Posted by CgullZ on December 17, 2012 at 4:42pm
Hello,
I am new to Drupal, and I need to add a jQuery code to all of my pages.
I read a few tutorials and managed to do it, but I'm not sure I did it the best way.
What I did is added this code in mysite/includes/common.inc in the function drupal_add_js:
'misc/drupal.js' => array(
'data' => 'misc/drupal.js',
'type' => 'file',
'scope' => 'header',
'group' => JS_LIBRARY,
'every_page' => TRUE,
'weight' => -1,
'preprocess' => TRUE,
'cache' => TRUE,
'defer' => FALSE,
),
//The code I added
'misc/test.js' => array(
'data' => '$(document).ready(function() {
alert("In");
});',
'type' => 'inline',
'scope' => 'header',
'group' => JS_LIBRARY,
'every_page' => TRUE,
'weight' => -1,
'preprocess' => TRUE,
'cache' => TRUE,
'defer' => FALSE,
),Any other way of doing this?
Thank you.
Comments
You should never modify core
You should never modify core files.
Easy way to add a js files to all makes is to add it to the scripts section of your themes .info file, see Working with JavaScript and jQuery