Tag Archives: Drupal Development

Drupal – Load External Javascript using drupal_add_js() @ 2

Here is another way to add the external .js file.

$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');

 

Done =)

Previous Post: Drupal – Load External Javascript using drupal_add_js() @ 1

Reference: Web Design by Tim Wooten – Load external js file in Drupal 6

Drupal – Load External Javascript using drupal_add_js() @ 1

If you want to include external .js file in your custom module, create the following file.
external.js

(function ($) {
  Drupal.behaviors.myModule = function(context) {
    var externalScript = $('<script></script>').attr('type','text/javascript').attr('src', 'http://example.org/example.js');
    $('body').append(externalScript);
  }
}(jQuery));

Continue reading Drupal – Load External Javascript using drupal_add_js() @ 1