Bennu Bird Media - Making cents from non-cents

Bennu Bird Media

  • about bennu bird
  • contact
  • hot drops
  • professional standards
  • events calendar
  • site map
Home › Blogs › charles.russell's blog

Adding JavaScript to Drupal

  • View
  • Attendees

charles.russell — Mon, 07/05/2010 - 21:49

JavaScript is gaining increasing importance in web development today. This is for several reasons. First, it is the only client scripting language that has been implemented in one form or another across all of the major browsers. It can be used to provide animation, manipulate your HTML, change your CSS, and send communications to the browser without form submission. As discussed in my previous posting, JavaScript is important in Drupal as well. For the next several postings I will be talking about JavaScript so it may be useful for you to know at least a basic method of attaching JavaScript to your site.

In traditional web development adding JavaScript is easy. All you need to do is add <script type=”text/javascript” src=”myScript.js”></script> into the head section of your HTML/XHTML document. Drupal is different. As with almost anything Drupal, there are several methods to attach JavaScript to your content. That is because the JavaScript you use may go to just one node. It may be theme specific, or be theme independent. How you apply the JavaScript in a Drupal application is going to be dependent on how you use it. The easiest is to use a theme based solution. The easiest theme based solution is to create a script.js file and add your code in it. Every Drupal 6 theme is supposed to look for this file and you can place any custom JavaScript you need in it. But just because themes is supposed to support script.js doesn't mean all do. Fortunately there is a quick fix if your theme is not picking up the script.js file. Find the file in the base directory of your theme that has the name of your theme with a .info extension. You can then add the line scripts []= scripts.js to it and everything will work fine. Later on I will discuss other methods of adding custom script, including more on the scripts [] in the .info file. For now just know that the scripts.js file can hold any JavaScript you need across your site.

  • charles.russell's blog
  • Add new comment

User login

  • Request new password

Powered by Drupal, an open source content management system
  • about bennu bird
  • contact
  • hot drops
  • professional standards
  • events calendar
  • site map