Including JS in a drupal page
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 ?.
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.
I'd just include the js in the .info file for your theme. It's the best way to include scripts.
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.
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
精彩评论