By sumgai on
I wanted to add some javascript to a page from another website, so I put in:
drupal_add_js("http://www.somesite.com/stuff/mycode.js", 'module')
but the function added $base_url to the front, which broke the url.
I made a simple change to drupal_get_js in common.inc that seems to solve the problem:
switch ($type) {
case 'setting':
$output .= '<script type="text/javascript">Drupal.extend({ settings: '. drupal_to_js(call_user_func_array('array_merge_recursive', $data)) ." });</script>\n";
break;
case 'inline':
foreach ($data as $info) {
$output .= '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .'>'. $info['code'] ."</script>\n";
}
break;
//mitch - need something that doesn't make a relative path!
case 'remote':
foreach ($data as $path => $info) {
$output .= '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .' src="'. check_url($path) . ($info['cache'] ? '' : '?'. time()) ."\"></script>\n";
}
break;
//mitch
default:
foreach ($data as $path => $info) {
$output .= '<script type="text/javascript"'. ($info['defer'] ? ' defer="defer"' : '') .' src="'. check_url(base_path() . $path) . ($info['cache'] ? '' : '?'. time()) ."\"></script>\n";
}
}
What do you think?
Is there a better way to solve this?
Thanks,
Mitch