I have some items I want to add as nodes that require that a piece of JS be added to the head of the node specifically for the node and nowhere else.

How would I create a field in the node creation form that allowed me to copy and paste items into the head tags of just that node?

Comments

WorldFallz’s picture

when i need to add js to a node i use the php code input format and the drupal_add_js function

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

JeremyL’s picture

Worked perfect, thanks

WorldFallz’s picture

excellent-- you're welcome ;-)

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

dalehgeist’s picture

I'm not sure about the syntax I should be using with drupal_add_js(). I want to do the same thing: load an external javascript file into the head tag for a specific page.

I enabled the PHP input type and put the following code into the body field of the node:

<?php drupal_add_js("sites/all/themes/mytheme/myscript.js");?>

Result: when I View Source, myscript.js is not referenced. I have a feeling I'm not implementing drupal_add_js() correctly, but I can't quite decode the drupal_add_js() API.

thanks,
Dale

dalehgeist’s picture

I had "Compress Javascript files" turned on, so all my scripts were getting squashed into one, therefore I could not see them in View Source. But the script itself did load.