0

Im using Drupal 6.19.In my Drupal page i have the input format set to PHP code.I have included a JS file using the following line of PHP:

print "<script src=\"my_site_includes/js/script.js\"> </script>";

The page is set as the front page and attached to a primary menu item.But the js is not executed when i access the site. However if i edit the page and click save, the js executes. This is really strange, as i have to edit the page and hit save for the js to execute. What could be going wrong here ?.

MrSmith42
10.2k6 gold badges42 silver badges52 bronze badges
asked Nov 9, 2010 at 9:21

4 Answers 4

7

Manipulating Drupal in such a way is not a good idea. Be sure to look into drupal_add_js(). You can call in in a custom module or from a template.

answered Nov 9, 2010 at 9:26
Sign up to request clarification or add additional context in comments.

1 Comment

To add a reason why for the above comment - when you enable JS minification in the performance tab, all JS included in the page through drupal_add_js() will be mashed together, but if you hard code the JS with <script> tags, it will not.
3

I'd just include the js in the .info file for your theme. It's the best way to include scripts.

answered Nov 9, 2010 at 9:34

2 Comments

Thanks for the reply. I put my script in the js folder of my theme and included the js in the .info file of my theme using scripts[] = js/script.js. But the script is not getting included. Please help
Try to clear the cache (at the bottom of the Performance page). By the way, if you place "script.js" at the root folder of your theme, you don't even need to add it in the .info, Drupal 6 adds it automatically if it detects such a file (however in Drupal 7, it needs to be placed in the .info, so it's safer to include it).
0

While including in template add it before to </body> instead of head . It is better to call for the script as late as possible, so that the loading of images and other components will not be delayed and may improves loading time.

answered Nov 11, 2010 at 9:53

Comments

0

There are two ways you can include js files in Drupal. First is include the js file in the theme info file and the second way is to use the drupal function drupal_add_js. If you want to look at the detailed information about the drupal_add_js then visit this link

answered Sep 19, 2011 at 10:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.