I've got a question about module building and including JS. I'm working on a D6 custom module, and for JS files I'm including from within my mod drupal_add_js(drupal_get_path('module', 'ingsavingsmap') .'/js/effects.js');
works just fine.

The question I have is: I'm trying to include jquery from the jquery site. I know: drupal_add_js(drupal_get_path('module', 'ingsavingsmap') .'http://code.jquery.com/jquery- latest.js');

is very wrong for a number of reasons, but I don't know how to go about adding JS from a URL. Also, is it advisable to event be doing it this way? or should I just keep it all within the mod.

Any help or direction to documentation would be appreciate Thanks! Steph

  • I think you'll really struggle to get the latest version of jQuery into a Drupal 6 site (without getting a lot of JS errors). What are you using that depends on the latest version?
    – Clive
    Jan 9 '13 at 18:02
  • I've got a lot of other effects, and yes I know it's against the Drupal Way. I'm hoping that because the mod produces a page its by itself enough to not cause conflicts. Any Ideas?
    – StephanieF
    Jan 9 '13 at 18:16
  • 1
    It's been discussed quite a few times (more for D7 than D6) and I think the jQuery multi module is probably the best bet. But these posts (and their various links) might help too: drupal.stackexchange.com/questions/12911/…, drupal.stackexchange.com/questions/28820/…. I love that you capitalised "Drupal Way" by the way, sounds like a good title for a book...
    – Clive
    Jan 9 '13 at 18:23


For those who need to do this in D7, its as simple as

drupal_add_js('http://example.com/example.js', 'external');


I can not take credit for this example but found this to be rather nice and easy way of dealing with external js files.

$external_js = 'http://www.example.com/a.js';
drupal_add_js('document.write(unescape("%3Cscript src=\''. $external_js . '\' type=\'text/javascript\'%3E%3C/script%3E"));', 'inline');

Found this via http://www.wootenswebdesign.com/load-external-js-file-drupal-6

  • I'm afraid it really isn't that simple. Drupal already includes jQuery so without extra work you'll get conflicts
    – Clive
    Jan 9 '13 at 18:57
  • ugh. that is what i get for again not reading the whole question. i see where i made a mistake. however, this should still work just nto with including jquery.
    – au_stan
    Jan 9 '13 at 18:58
  • 1
    Yeah for including anything other than jQuery externally this is spot on :)
    – Clive
    Jan 9 '13 at 19:05
  • I agree with clive on the conflicts, and I know I'm going to have to do a bunch of troubleshooting. Right now this actually works "drupal_add_js('code.jquery.com/jquery-latest.js');" I do have some stuff to figure out still but I'll let you know wat happens and if it's successful or not, as well as accept an answer. Thanks all! I really appreciate the help!
    – StephanieF
    Jan 9 '13 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.