By erikhanson on
I have been beating my head against this all day. I have an external JavaScript file that I need to run a fairly complex calculator. I want the run the calculator in a page node. Whenever I add the external js by using the drupal_add_js line in my template.php file it conflicts (I think) with some of the other js files.
The conflict is only apparent and an issue in the admin section and when creating content.
All I want to do is to add the js to the one page and nowhere else.
I have no idea which of Drupals other js files this thing isn't playing nice with and am not good enough at js to trouble shoot it anyway, so I figure my best bet is isolation. Anyone have a good idea how to do this?
Comments
try something list this
try something like this to get it to load on just one page...
This will only load for the one path.
--
Matt
http://www.mattfarina.com
Thanks!
Thank you, thank you, and thank you. It worked!
I really appreciate it!
some lessons needed
pls teach me how to make javascript tabbed pages...collapsible READ MORE etc...on the page...to prevent more page refreshes....this way...we can overcome some speed issues ..pls help...
i know nothing of javascript etc..so pls help me with basic instructions..and some examples to figure out.
visual jquery
http://www.visualjquery.com
--
Matt
http://www.mattfarina.com
A Small Clarification
Thanks so much for the code! I just wanted to add a tidbit for those who might need a little help. For the code in the post above, you need to add it to your template.php file, and you might need to remove the opening <?php part. Also, change /path/to/node to your node's path (obviously), and change 'somefile.js' to the location of your file, relative to the site root. In my case, I had the .js file in my theme folder, so I put in /sites/all/themes/theme-name/somefile.js
__________________
Personal site: www.jeffgeerling.com
I'm having issues adding JS
I'm having issues adding JS files to a node. It just isn't adding them...
I've tried this in the node:
and these in thetemplate.php
Does anyone have any idea
Does anyone have any idea why it isn't working?
bump
bump
Why the '_' before
Why the '_' before drupal_add_js? I just add js to a node by using the php input type and adding the files with a drupal_add_js for each file. Works fine.
===
"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." - Ben Franklin
"Search is your best friend." - Worldfallz
You mean... simply like this
You mean... simply like this in the node?
It's not working...
I've not tried it with an
I've not tried it with an absolute URL but something like this:
===
"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." - Ben Franklin
"Search is your best friend." - Worldfallz
Okay. Maybe I should try
Okay. Maybe I should try putting the files in my theme and linking them that way...
Further clarification & question
Just in case anyone else has the same issue, for my XAMP install the path to the node starts at localhost while the path to the script starts from the drupal directory. Not sure why but had to fiddle with it for a while before it worked. This is what worked:
if ($_SERVER['REQUEST_URI'] == '/drupal/?q=node/13') {
drupal_add_js('sites/all/radio_checker.js');
}
Question: This requires running a query for every page loaded throughout the site even though the script is only used on one page. Does anyone know of a less resource intense solution? For example, is it possible to just have a script load when needed, such as on a button click?
Thanks!