Load external JavaScript Files in Drupal 6

Drupal 6 doesn't allow you to use drupal_add_js() to load external JavaScript Files (Drupal 7 does by the way!). This is a pity as js aggregation (see admin/settings/performance) wouldn't work for external files this way.

But there is a little hack that helps:

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

Links:
http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ad...
http://www.wootenswebdesign.com/load-external-js-file-drupal-6





Powered by Drupal7