1

I am using javascript for some of the html pages. Where should I store the javascript files in my drupal folder.

1 Answer 1

3

If it's a theme, and if you are defining scripts in .info file, keep the .js files in scripts folder of your theme folder (e.g sites/all/themes/mytheme/scripts). You don not have to define the whole path. Just enter the relative path to the .info file (scripts/myscript.js) and it will get included in the entire site.

if you are using drupal_add_js, in a custom module, the common practice is to keep the file in module's folder. Set it as drupal_get_path.

Although it's not recommended, if you are hardcoding the script in html.tpl.php or page.tpl.php folder, I'd place the js file in theme folder and use a drupal_get_path to get the actual path.

2
  • its not a theme. only for four html pages i am using the js. I have uploaded using upload field button in the site. But they its getting automatically renamed to js.txt file. Where should i keep them .
    – Cindrella
    Jul 26, 2012 at 3:11
  • 1
    You will need to upload it using FTP. In most fields, you cannot upload executable files. even strict, you can upload only few allowed file types.
    – AKS
    Jul 26, 2012 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.