By sopko on
I searched four hours on how to do this and could not find the answer.
I want to add some simple java script and functions to my nodes. I want
to call the javascript functions from a file in the section as
it is supposed to be called:
Comments
Oops, bad format, more info...
I want to add the script src=sites/all/js/my.js tag
to the <head> section in drupal to call my javascript functions.
It is recommended to put your functions in the <head> section
Like this:
Perhaps this could help? -
Perhaps this could help?
- Corey
Just open the folder for the
Just open the folder for the theme you are using and find the file that has your HEAD tags (the default themes have them in the page tpl file I believe). Simply add your code to that file and the JS functions should attach to all your pages.
Using the drupal_add_js()
Using the drupal_add_js() function is the proper way of doing this.
Here is what worked in my case
I am using the contributed newsportal them.
First I tried placing the drupal_add_js('sites/all/js/my.js')
function in the page.tpl.php file. This did not work, it did not produce anything.
Manually putting the script section:
<script type="text/javascript" src=sites/all/js/my.js>
in the page.tpl.php file worked fine.
I then put the drupal_add_js('sites/all/js/my.js'); function in the
template.php file that came with the theme and it aslo worked fine.
That is it put in the proper script tag in the header section. I will
go with this. Thanks.
Putting it in page.tpl.php
Putting it in page.tpl.php indeed will not work for drupal_add_js. It needs to go in your theme's template.php.
Thanks!
Very simple - and helpful!
java script function ??
I am trying to implement the following script below
http://www.dynamicdrive.com/dynamicindex4/stepcarousel.htm
in page can pls help me..
how do i add the script on template.php
function drupal_add_js('sites/all/js/my.js'); is this the right way???
You can add javascript to
You can add javascript to head by using theme_preprocess_html()